API reference@evolu/commonlocal‑first/Schema › EvoluSchema

type EvoluSchema = ReadonlyRecord<string, TableSchema>;

Defined in: packages/common/src/local-first/Schema.ts:95

Defines the schema of an Evolu database.

Column types are Standard Schema v1 compatible — use Evolu Type, Zod, Valibot, ArkType, or any library that implements Standard Schema.

Table schema defines columns that are required for table rows. For optional columns, use a schema whose output type includes null.

Example

import * as z from "zod";
import {
  id,
  NonEmptyTrimmedString100,
  nullOr,
  SqliteBoolean,
} from "@evolu/common";

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

const Schema = {
  todo: {
    id: TodoId,
    title: NonEmptyTrimmedString100,
    isCompleted: nullOr(SqliteBoolean),
  },
};
expectOk(Schema.todo.title.fromUnknown("Write docs"), "Write docs");

// Zod, or another Standard Schema library
const ZodSchema = {
  todo: {
    id: TodoId,
    title: z.string().min(1).max(100),
    isCompleted: z.union([z.literal(0), z.literal(1)]).nullable(),
  },
};
expect(ZodSchema.todo.title.safeParse("Write docs").success).toBe(true);