d4fd67f4d2688bc57a8a8650ea34a1586526dbb8
Architecture review session resolving all high-priority open questions and filling documentation gaps identified during review: Decisions resolved: - OQ-04: Flat props with inner escape hatch for column validation (ADR-007) - OQ-05: PG enum pre-declaration returns enums and tables (ADR-008) - OQ-06: Render results accumulate in root.ctx (resolved in hosts.md) - Column references vs fk: references is shorthand, explicit fk takes precedence (ADR-006) - ADR-001, 002, 003 promoted from Proposed to Accepted (probe-validated) Documentation improvements: - Complete DbColumnType mapping tables for all 14 types across 3 dialects - Define ColumnMeta, TableMeta, IndexMeta, FkMeta types in elements.md - Document inner prop, mode prop, and default prop semantics - Add PgRootCtx, SqliteRootCtx, MySqlRootCtx context types - Consolidate schema.md and module.md (remove duplication) - Add end-to-end pipeline walkthrough to README - Add glossary with 13 terms - Add error handling strategy - Remove duplicate content from hosts.md (cross-ref elements.md)
@alkdev/dbtype
Schema-first multi-dialect database type system. Define your schema once as a UJSX element tree, validate it with TypeBox, and render it to any Drizzle dialect.
Based on drizzle-typebox by the Drizzle Team, adapted for use with @alkdev/typebox and @alkdev/ujsx.
Install
npm install @alkdev/dbtype @alkdev/typebox @alkdev/ujsx
npm install drizzle-orm # peer dependency, only the dialects you use
Architecture
See docs/architecture/README.md for the full architecture specification.
Core Principle
The element tree is the schema. The module is the bundle. The host is the dialect.
- UJSX elements (
<table>,<column>) define schemas with composable function components Type.Moduleholds all tables, relations, and derived schemas with automaticType.RefresolutionHostConfigrenders the same tree tosqliteTable,pgTable, ormysqlTable
Quick Example
import { Type, FormatRegistry } from '@alkdev/typebox'
import { Value } from '@alkdev/typebox/value'
import { h, createComponent } from '@alkdev/ujsx'
// Register custom format validators
FormatRegistry.Set('uuid', (v) => /^[0-9a-f]{8}-[0-9a-f]{4}-...$/i.test(v))
// Composable column components
const IdColumn = createComponent('IdColumn', () =>
h('column', { name: 'id', type: 'uuid', primaryKey: true, default: 'uuid' })
)
const AuditColumns = createComponent('AuditColumns', () => [
h('column', { name: 'createdAt', type: 'timestamp', notNull: true, default: 'now' }),
h('column', { name: 'updatedAt', type: 'timestamp', notNull: true, default: 'now' }),
])
// Define a table
const UsersEl = h('table', { name: 'users' },
h(IdColumn, {}),
h('column', { name: 'name', type: 'string', notNull: true }),
h('column', { name: 'email', type: 'string', notNull: true }),
h(AuditColumns, {}),
)
// Extract to Type.Module for validation
const { name, schema } = extractTable(UsersEl)
const M = Type.Module({ Users: schema, UsersRelations: Type.Object({ tasks: Type.Array(Type.Ref('Tasks')) }) })
const Users = M.Import('Users')
Value.Check(Users, { id: '...', name: 'alice', email: 'a@b.com', createdAt: 1, updatedAt: 1 })
// → true
Current State
Phase 0: Exploration — Architecture probing complete, implementation not started.
The current src/ contains the forked drizzle-typebox code. The new architecture (UJSX elements, Type.Module, HostConfig) is designed and validated but not yet implemented.
Attribution
Based on drizzle-typebox by the Drizzle Team, licensed under Apache-2.0.
Description
Languages
TypeScript
100%