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