TinyBase logoTinyBase β

toTablesSchema

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

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

A mapping of table IDs to Valibot object schemas.

returnsTablesSchema

A TinyBase TablesSchema.

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

Example

This example converts Valibot schemas to TinyBase format.

import {createStore} from 'tinybase';
import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
import {boolean, fallback, number, object, string} from 'valibot';

const schematizer = createValibotSchematizer();

const tablesSchema = schematizer.toTablesSchema({
  pets: object({
    species: string(),
    age: number(),
    sold: fallback(boolean(), 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