import { schema, table, t, type DbView, type TableSchema } from './index.ts'; import type { Table, TableOpts, UntypedTableDef } from '../lib/table.ts'; import type { TableToSchema, UntypedSchemaDef } from '../lib/schema.ts'; // Erasing a legacy schema's concrete table types must not remove mutations. export function clearErasedDb(view: DbView) { return view.table.clear(); } // Existing generic helpers must retain the complete Table API. export function clearTable(handle: Table) { return handle.clear(); } export function deleteInsertedRow( handle: Table, row: Parameters['insert']>[0] ) { return handle.delete(handle.insert(row)); } const row = { id: t.u64().primaryKey(), note: t.string().index() }; const options: TableOpts = { public: true }; const widenedOptions = table(options, row); const widenedSchema: TableSchema = widenedOptions; const db = schema({ widenedOptions, widenedSchema }); type OrdinaryDef = TableToSchema<'widenedOptions', typeof widenedOptions>; db.reducer(ctx => { for (const handle of [ctx.db.widenedOptions, ctx.db.widenedSchema]) { handle.insert({ id: 1n, note: 'hello' }); handle.id.update({ id: 1n, note: 'updated' }); handle.id.delete(1n); handle.note.delete('updated'); handle.delete({ id: 1n, note: 'hello' }); clearTable(handle); deleteInsertedRow(handle, { id: 1n, note: 'hello' }); handle.clear(); } });