TinyBase logoTinyBase

toTablesSchema

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

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

A mapping of table IDs to TypeBox object schemas.

returnsTablesSchema

A TinyBase TablesSchema.

This method extracts basic type information (string, number, boolean), basic type unions, primitive enums and literals, default values, nullable flags, and required flags from TypeBox schemas. Complex validation rules like min/max, patterns, formats, and custom validators are ignored.

Example

This example converts TypeBox schemas to TinyBase format.

import {Type} from '@sinclair/typebox';
import {createStore} from 'tinybase';
import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';

const schematizer = createTypeBoxSchematizer();

const tablesSchema = schematizer.toTablesSchema({
  pets: Type.Object({
    species: Type.String(),
    age: Type.Number(),
    sold: Type.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