> For the complete documentation index, see [llms.txt](https://docs.lingoql.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lingoql.com/sub0/creating-database-models/anatomy-of-models.md).

# Anatomy of Models

Use this reference to understand Sub0 database model properties, field types, relationships, and indexing.

### Core field properties

| Property         | Type      | Description                                                  |
| ---------------- | --------- | ------------------------------------------------------------ |
| `type`           | `String`  | Defines the data type of the field. Required for all fields. |
| `optional`       | `Boolean` | If `true`, the field may be `null`. Defaults to `false`.     |
| `primary_key`    | `Boolean` | Marks the field as the primary key of the model.             |
| `auto_increment` | `Boolean` | Enables automatic value generation for numeric primary keys. |
| `max_length`     | `Number`  | Sets the maximum allowed length for string values.           |
| `indexable`      | `Boolean` | Creates a database index for the field.                      |
| `fts`            | `Boolean` | Enables full-text search indexing for the field.             |
| `foreign_key`    | `Object`  | Declares a relationship to another model.                    |

### Foreign key properties

Use `foreign_key` to reference another table or collection.

| Sub-property | Type     | Description                              |
| ------------ | -------- | ---------------------------------------- |
| `of`         | `String` | The target model to reference            |
| `key`        | `String` | The referenced field on the target model |

### Supported field types

| `type` Value  | Description                               |
| ------------- | ----------------------------------------- |
| `Number`      | Integer numeric value                     |
| `Float`       | Floating-point numeric value              |
| `String`      | Text value                                |
| `Boolean`     | Boolean (`true` / `false`)                |
| `DateTime`    | Timestamp value                           |
| `JSON_OBJECT` | Structured object with defined properties |
| `JSON_ARRAY`  | Array of values of a single type          |

### JSON object fields

Use `type: "JSON_OBJECT"` for nested structured data. Each object must define `properties`.

#### Object properties

| Property     | Type      | Description                             |
| ------------ | --------- | --------------------------------------- |
| `properties` | `Object`  | Defines the schema of the nested object |
| `optional`   | `Boolean` | Allows the entire object to be `null`   |

Nested fields inside `properties` follow the **same anatomy rules** as top-level fields.

### JSON array fields

Use `type: "JSON_ARRAY"` for lists of values with one field type.

#### Array properties

| Property        | Type      | Description                                     |
| --------------- | --------- | ----------------------------------------------- |
| `property_type` | `String`  | Defines the type of values allowed in the array |
| `optional`      | `Boolean` | Allows the array to be `null`                   |

> `property_type` is **only valid for JSON arrays** and is used to qualify the type of each array element.

### Indexing and search properties

| Property    | Description                                         |
| ----------- | --------------------------------------------------- |
| `indexable` | Enables standard database indexing                  |
| `fts`       | Enables full-text search indexing (where supported) |

### Notes

* All fields must declare `type`
* Nested fields behave exactly like top-level fields
* Constraints and indexes compile to the underlying database engine
* Model definitions are database-agnostic and work across **MongoDB, MySQL/MariaDB, and PostgreSQL**

Next, see [Creating Models](/sub0/creating-database-models/creating-models.md) for real-world database model examples.


---

# 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:

```
GET https://docs.lingoql.com/sub0/creating-database-models/anatomy-of-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
