toTablesSchema
The toTablesSchema method converts a mapping of Effect Schema struct schemas into a TinyBase TablesSchema.
toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema| Type | Description | |
|---|---|---|
schemas | {[tableId: string]: any} | A mapping of table IDs to Effect Schema struct schemas. |
| returns | TablesSchema | A TinyBase |
This method extracts basic type information (string, number, boolean), nullable flags, and optional flags from Effect schemas. Default values are not supported as they exist in Effect's runtime transformations, not in the schema AST. Complex validation rules, transformations, and refinements are ignored.
Example
This example converts Effect Schema schemas to TinyBase format.
import {Boolean, Number, String, Struct} from 'effect/Schema';
import {createStore} from 'tinybase';
import {createEffectSchematizer} from 'tinybase/schematizers/schematizer-effect';
const schematizer = createEffectSchematizer();
const tablesSchema = schematizer.toTablesSchema({
pets: Struct({
species: String,
age: Number,
sold: Boolean,
}),
});
const store = createStore().setTablesSchema(tablesSchema);
store.setRow('pets', 'fido', {species: 'dog', age: 3, sold: false});
console.log(store.getRow('pets', 'fido'));
// -> {species: 'dog', age: 3, sold: false}
Since
v7.1.0