TinyBase logoTinyBase β

toTablesSchema

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

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

A mapping of table IDs to ArkType object schemas.

returnsTablesSchema

A TinyBase TablesSchema.

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

Example

This example converts ArkType schemas to TinyBase format.

import {type} from 'arktype';
import {createStore} from 'tinybase';
import {createArkTypeSchematizer} from 'tinybase/schematizers/schematizer-arktype';

const schematizer = createArkTypeSchematizer();

const tablesSchema = schematizer.toTablesSchema({
  pets: type({
    species: 'string',
    age: '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