> For the complete documentation index, see [llms.txt](https://smuddgge.gitbook.io/squishy-library/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smuddgge.gitbook.io/squishy-library/database/summary.md).

# Summary

{% tabs %}
{% tab title="Config" %}
Add this file to your resource folder.

{% code title="database.yml" overflow="wrap" %}

```yaml
# Database Library Author: Smudge
# File: database.yml
# Last Changed Library Version: 1.0.0

should_reconnect_every_cycle: true
reconnect_cooldown_millis: 2000
will_reconnect: true
time_between_requests_millis: 100
max_requests_pending: 40

sqlite:
  enabled: true
  path: "plugins/CozyJoinLeave/database.sqlite3"

mysql:
  enabled: false
  connection_string: "address:port"
  database_name: ""
  username: ""
  password: ""

mongo:
  enabled: false
  connection_string: "" # example: "mongodb+srv://Name:Password@Name.?.mongodb.net/?retryWrites=true&w=majority"
  database_name: ""
```

{% endcode %}
{% endtab %}

{% tab title="Create Database" %}
Load the config file and create the database.

{% code title="" overflow="wrap" %}

```java
Configuration databaseConfig = new YamlConfiguration(
    this.getPlugin().getDataFolder(),
    "database.yml"
);
databaseConfig.setResourcePath("database.yml");
databaseConfig.load();

Database database = new DatabaseBuilder(
    this.databaseConfig
).create().connect();
```

{% endcode %}
{% endtab %}

{% tab title="Records" %}
{% code overflow="wrap" %}

```java
public class ExampleRecord implements Record<Example2Record> {

    public static final @NotNull String IDENTIFIER_KEY = "identifier";
    public static final @NotNull String STRING_KEY = "value";

    private final @Field(IDENTIFIER_KEY) @Primary @NotNull String identifier;
    private @Field(STRING_KEY) String string;
    
    public ExampleRecord(@NotNull String identifier) {
        this.identifier = identifier;
    }
    
    @Override
    public @NotNull ConfigurationSection convert() {
        MemoryConfigurationSection section = new MemoryConfigurationSection();
        section.set(STRING_KEY, string);
        return section;
    }

    @Override
    public @NotNull Example2Record convert(
        @NotNull ConfigurationSection section) {
        
        this.string = section.getString(STRING_KEY);
        return this;
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Tables" %}
Define the table.

{% code overflow="wrap" %}

```java
public class ExampleTable extends Table<ExampleRecord> {

    public static final @NotNull String TABLE_NAME = "example";

    @Override
    public @NotNull String getName() {
        return ExampleTable.TABLE_NAME;
    }

    @Override
    public @NotNull ExampleRecord createEmpty(@NotNull PrimaryFieldMap identifiers) {
        return new ExampleRecord(
            identifiers.getString(ExampleRecord.IDENTIFIER_KEY)
        );
    }
}
```

{% endcode %}

Create the table in the database.

```java
database.createTable(new ExampleTable());
```

{% endtab %}

{% tab title="Query" %}

```java
ExampleRecord record = database.getTable(ExampleTable.class)
    .getFirstRecord();
```

{% endtab %}
{% endtabs %}

***

<table><thead><tr><th>Database</th><th>Status</th><th data-hidden></th></tr></thead><tbody><tr><td><code>SQLite</code></td><td>Implemented</td><td></td></tr><tr><td><code>MySQL</code></td><td>Implemented</td><td></td></tr><tr><td><code>MongoDB</code></td><td>Implemented</td><td></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://smuddgge.gitbook.io/squishy-library/database/summary.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
