toTablesSchema
The toTablesSchema method converts a mapping of Valibot object schemas into a TinyBase TablesSchema.
toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema| Type | Description | |
|---|---|---|
schemas | {[tableId: string]: any} | A mapping of table IDs to Valibot object schemas. |
| returns | TablesSchema | A TinyBase |
This method extracts basic type information (string, number, boolean), basic type unions, primitive picklists and literal unions, fallback values, nullable flags, and required 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