TinyBase logoTinyBase

toTablesSchema

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

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

A mapping of table IDs to Yup object schemas.

returnsTablesSchema

A TinyBase TablesSchema.

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

Example

This example converts Yup schemas to TinyBase format.

import {createStore} from 'tinybase';
import {createYupSchematizer} from 'tinybase/schematizers/schematizer-yup';
import {boolean, number, object, string} from 'yup';

const schematizer = createYupSchematizer();

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