Overview

In Basic, we declare schemas in a JSON format as part of the basic.config.ts or basic.config.js file that lives in your repository. It would follow this general format:

The top level requires three parameters:

project_id

project_id
string
required

This is your project ID, which you can find in the Basic dashboard, or will be auto-generated for you if you had used the CLI to create your project.

version

version
int
required

This will be used for versioning your schema. It should be an integer that starts at 0 and increments by 1 for each new version.

Versionining of schemas is currently in development. This value should remain at 0.

Tables

Let’s double click into the tables to learn how they are declared in the schema.

Each table is declared as an object where the key is the table name and the value is an object with the following two parameters:

type

type
string
required

This refers to the type of database table you are creating. At the moment, Basic only supports collection, which will operate similarly to MongoDB collections.

fields

fields
object
required

Fields are the columns of the table. They will be declared as an object of objects. Learn more about the fields below.

Fields

Each field is declared as an object where the key is the field name and the value is an object with the following 2 parameters:

type

type
string
required

This is the data type of the field. Basic supports the following field types: string, int, boolean, json, text.

indexed

indexed
boolean
required

This lets you control if the field should be indexed in the user’s client database for local-first benefits. For now, this should always be set to true.

Example

When put all together, your schema could look like this:

basic.config.ts
export const schema = {
    project_id: '1234567890',
    version: 0,
    tables: {
        comments: {
            type: 'collection',
            fields: {
                title: { 
                    type: 'string',
                    indexed: true
                },
                body: { 
                    type: 'string',
                    indexed: true
                },
                rating: { 
                    type: 'int',
                    indexed: true
                }
            }
        },
        items: {
            type: 'collection',
            fields: {
                name: { 
                    type: 'string',
                    indexed: true
                },
                quantity: { 
                    type: 'int',
                    indexed: true
                },
                available: {
                    type: 'boolean',
                    indexed: true
                }
            }
        }
    }
}