# Records

```java
public class YourRecordName implements Record<YourRecordName> {
```

{% tabs %}
{% tab title="Primary Fields" %}
{% hint style="success" %}
Primary Fields = Primary Keys
{% endhint %}

Primary fields represent a unique identifier for the record. \
They are declared with the @Primary annotation.

```java
public static final @NotNull String IDENTIFIER_KEY = "identifier";

private final @Field(IDENTIFIER_KEY) @Primary @NotNull String identifier;
```

{% endtab %}

{% tab title="Normal Fields" %}

```java
public static final @NotNull String STRING_KEY = "value";
public static final @NotNull String BOOL_KEY = "bool";
public static final @NotNull String OBJECT_KEY = "object";

private @Field(STRING_KEY) String string;
private @Field(BOOL_KEY) boolean bool;
private @Field(OBJECT_KEY) ExampleObject object;
```

{% code title="This could be any class." overflow="wrap" %}

```java
public class ExampleObject {
    private final @NotNull String testString = "test";
    private int testInt = 123;
}
```

{% endcode %}
{% endtab %}

{% tab title="Foreign Fields" %}
{% hint style="success" %}
Foreign Fields = Foreign Keys
{% endhint %}

Foreign Fields are used to connect records. In SQL this is called a relational database.

{% code overflow="wrap" %}

```java
public static final @NotNull String OTHER_TABLE_IDENTIFIER 
    = "other_table_identifier";

@Field(OTHER_TABLE_IDENTIFIER)
@Foreign(
    table = OtherTable.TABLE_NAME, 
    tableField = OtherRecord.IDENTIFIER_KEY
)
private String foreign;
```

{% endcode %}
{% endtab %}
{% endtabs %}

<pre class="language-java"><code class="lang-java"><strong>    public TestRecord(@NotNull String identifier) {
</strong>        this.identifier = identifier;
        this.string = "The default value.";
        this.bool = true;
        this.object = new ObjectTest();
        this.foreign = "The default value.";
    }
</code></pre>

To read and write the record we fill in the convert methods. This is how it is "sterilized".

```java
    @Override
    public @NotNull ConfigurationSection convert() {
        ConfigurationSection section = new MemoryConfigurationSection();

        section.set(IDENTIFIER_KEY, this.identifier);
        section.set(TestRecord.STRING_KEY, this.string);
        section.set(TestRecord.BOOL_KEY, this.bool);
        section.set(TestRecord.OBJECT_KEY, this.object);
        section.set(TestRecord.OTHER_TABLE_IDENTIFIER, this.foreign);

        return section;
    }

    @Override
    public @NotNull TestRecord convert(@NotNull ConfigurationSection section) {
        this.string = section.getString(TestRecord.STRING_KEY);
        this.bool = section.getBoolean(TestRecord.BOOL_KEY);
        this.object = section.getClass(TestRecord.OBJECT_KEY, ObjectTest.class);
        this.foreign = section.getString(TestRecord.OTHER_TABLE_IDENTIFIER);
        return this;
    }
}
```

***

## Supported Types

<table><thead><tr><th width="166">Type</th><th width="164">Status</th><th>Description</th></tr></thead><tbody><tr><td>String</td><td>Implemented</td><td></td></tr><tr><td>Boolean</td><td>Implemented</td><td></td></tr><tr><td>Integer</td><td>Implemented</td><td></td></tr><tr><td>Long</td><td>Implemented</td><td></td></tr><tr><td>Float</td><td>Implemented</td><td></td></tr><tr><td>Double</td><td>Implemented</td><td></td></tr><tr><td>Default</td><td>Implemented</td><td>If there is a data type you want to use that isnt included above it will convert it into a json and store as a string.</td></tr></tbody></table>
