Skip to content

feat: make Drizzle ORM the default for Lakebase plugin#388

Draft
pkosiec wants to merge 1 commit into
mainfrom
pkosiec/lakebase-drizzle-by-default
Draft

feat: make Drizzle ORM the default for Lakebase plugin#388
pkosiec wants to merge 1 commit into
mainfrom
pkosiec/lakebase-drizzle-by-default

Conversation

@pkosiec
Copy link
Copy Markdown
Member

@pkosiec pkosiec commented May 18, 2026

Summary

Makes Drizzle ORM the default experience when scaffolding apps with the Lakebase plugin.

SDK

  • Add appkit.lakebase.drizzle(schema) helper using dynamic import() — zero cost if unused, full NodePgDatabase<TSchema> types when drizzle-orm is installed
  • drizzle-orm added as optional peerDep (no impact on users who don't use it)

Template

  • Rewrite todo CRUD example from raw SQL to Drizzle query builder
  • Add server/db/schema.ts (pgSchema + table definition + inferred types)
  • Add server/db/index.ts (ensureSchema + initDb via SDK helper)
  • Add drizzle.config.ts for drizzle-kit migrations
  • Add conditional drizzle-orm + drizzle-kit deps (only when lakebase feature is selected)
  • Add db:push, db:generate, db:migrate npm scripts

Docs

  • Add "Drizzle ORM (default)" section to Lakebase plugin docs with schema, queries, migrations, OBO examples
  • Expand @databricks/lakebase README Drizzle example

Key design decisions

  • SDK helper vs template helper: The drizzle() method lives in the SDK (not template) because template code is frozen at scaffold time — SDK code stays current with npm update
  • Dynamic import: drizzle-orm is loaded lazily via await import() so there's zero runtime cost for users who don't call .drizzle()
  • Type inference: TypeScript generates a lazy import("drizzle-orm/node-postgres").NodePgDatabase<TSchema> in .d.ts — resolved only when the method is called
  • RoutingPool compatibility: Drizzle checks constructor.name.includes('Pool') for transactions — RoutingPool passes this, so OBO routing works transparently
  • Conditional template deps: drizzle-orm and drizzle-kit use Go template conditionals ({{if .plugins.lakebase}}) in package.json — only installed when lakebase is selected

Test plan

  • SDK builds and typechecks cleanly
  • Template renders correctly via databricks apps init --template
  • All rendered Drizzle files are clean (no Go template syntax)
  • Existing tests pass (2527/2530, 3 pre-existing failures)
  • E2E: scaffold app with lakebase, deploy, verify CRUD operations work

- Add `appkit.lakebase.drizzle(schema)` SDK helper with dynamic import
  (drizzle-orm as optional peerDep, zero cost if unused)
- Rewrite template todo example to use Drizzle query builder
- Add template files: db/schema.ts, db/index.ts, drizzle.config.ts
- Add conditional drizzle-orm + drizzle-kit deps to template package.json
- Add drizzle-kit scripts (db:push, db:generate, db:migrate)
- Update Lakebase plugin docs with Drizzle section (schema, queries, migrations, OBO)
- Update @databricks/lakebase README with expanded Drizzle example

Signed-off-by: Pawel Kosiec <pawel.kosiec@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant