TinyBase logoTinyBase β

toTablesSchema

The toTablesSchema method converts a mapping of Zod object schemas into a TinyBase TablesSchema.

toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema
TypeDescription
schemas{[tableId: string]: any}

A mapping of table IDs to Zod object schemas.

returnsTablesSchema

A TinyBase TablesSchema.

This method extracts basic type information (string, number, boolean), default values, and nullable flags from Zod schemas. Complex validation rules like min/max, regex patterns, refinements, and transforms are ignored.

Example

This example converts Zod schemas to TinyBase format.

import {createStore} from 'tinybase';
import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
import {z} from 'zod';

const schematizer = createZodSchematizer();

const tablesSchema = schematizer.toTablesSchema({
  pets: z.object({
    species: z.string(),
    age: z.number(),
    sold: z.boolean().default(false),
  }),
});

const store = createStore().setTablesSchema(tablesSchema);
store.setRow('pets', 'fido', {species: 'dog', age: 3});
console.log(store.getRow('pets', 'fido'));
// -> {species: 'dog', age: 3, sold: false}

Since

v7.1.0