@dmc--98/dfe-drizzle
v0.1.3
Published
Drizzle ORM database adapter for Dynamic Form Engine
Readme
@dmc--98/dfe-drizzle
Drizzle ORM adapter for the Dynamic Form Engine.
Install
npm install @dmc--98/dfe-drizzle @dmc--98/dfe-server drizzle-ormRecommended Migration Flow
Use the adapter-aware CLI first, then hand off to your normal Drizzle migration commands:
npx dfe migrate plan --adapter drizzle
npx dfe migrate generate --adapter drizzle
npx drizzle-kit generate --name add_dfe_tables
npx drizzle-kit migrate
npx dfe migrate doctor --adapter drizzle --database-url "$DATABASE_URL"What each step does:
planinspects the project and tells you whether the DFE tables are already exposed through the schema entrypoint used bydrizzle.config.*.generatescaffolds a DFE schema entrypoint such assrc/db/dfe-schema.tswhen the project does not expose one yet.drizzle-kit generateanddrizzle-kit migrateremain the source of truth for applying the migration.doctorverifies local project wiring and, whenDATABASE_URLis provided, checks the live PostgreSQL tables and columns too.
If generate creates a new schema file, export or reference it through the schema entrypoint configured in drizzle.config.* before running Drizzle migrations.
Lower-Level Schema Options
Import the schema in your Drizzle config:
import {
dfeForms, dfeFormVersions, dfeSteps, dfeFields,
dfeFieldOptions, dfeSubmissions,
} from '@dmc--98/dfe-drizzle/schema'Or scaffold a starter entrypoint directly:
npx dfe add drizzle-schemaUsage
import { drizzle } from 'drizzle-orm/node-postgres'
import { DrizzleDatabaseAdapter } from '@dmc--98/dfe-drizzle'
const db = drizzle(pool)
const adapter = new DrizzleDatabaseAdapter(db)Schema (PostgreSQL)
The schema defines the same tables as the Prisma adapter using drizzle-orm/pg-core:
dfe_forms— form definitionsdfe_form_versions— versioned configurationsdfe_steps— step definitionsdfe_fields— field definitionsdfe_field_options— dynamic select optionsdfe_submissions— submission state
Custom API Contract Execution
Same pattern as Prisma — provide your own executor:
const adapter = new DrizzleDatabaseAdapter(db, {
executeApiContract: async (contract, body) => {
if (contract.resourceName === 'Employee') {
const [row] = await db.insert(employees).values(body).returning()
return row
}
throw new Error(`Unknown resource: ${contract.resourceName}`)
},
})Links
- Source: packages/drizzle
- Docs source: docs/packages/drizzle.md
- Issues: https://github.com/dmc-98/dynamic-form-engine/issues
