API Reference / @evolu/common / Evolu/Internal / EvoluSchema

Type Alias: EvoluSchema

type EvoluSchema = ReadonlyRecord<string, ReadonlyRecord<string, Type<any, any, any, any, any>> & object>;

Defined in: packages/common/src/Evolu/Schema.ts:79

Defines the schema of an Evolu database.

  • Each top-level key represents a table name.
  • The value for each table name is a record of column names mapped to their respective data types, defined by Type.
  • Each table must include a mandatory id column of type Id.
  • No table may contain DefaultColumns.

Table schema defines columns that are required for table rows. For not required columns, use nullOr.

Example

const TodoId = id("Todo");
type TodoId = typeof TodoId.Type;

const TodoCategoryId = id("TodoCategory");
type TodoCategoryId = typeof TodoCategoryId.Type;

const NonEmptyString50 = maxLength(50)(NonEmptyString);
type NonEmptyString50 = typeof NonEmptyString50.Type;

// Database schema.
const Schema = {
  todo: {
    id: TodoId,
    title: NonEmptyString1000,
    isCompleted: nullable(SqliteBoolean),
    categoryId: nullable(TodoCategoryId),
  },
  todoCategory: {
    id: TodoCategoryId,
    name: NonEmptyString50,
    json: nullable(SomeJson),
  },
};

Was this page helpful?