TinyBase logoTinyBase β

toTablesSchema

The toTablesSchema method converts a mapping of Effect Schema struct schemas into a TinyBase TablesSchema.

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

A mapping of table IDs to Effect Schema struct schemas.

returnsTablesSchema

A TinyBase TablesSchema.

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