boxfw-db
v0.3.0
Published
Box Framework — first-class Drizzle ORM integration, migration runner, and connection helpers
Downloads
877
Maintainers
Readme
boxfw-db
First-class Drizzle ORM integration for Box Framework — middleware, migration runner, and connection helpers for Bun SQLite, Cloudflare D1, and PostgreSQL.
Installation
bun add boxfw-dbRequires
boxfw-coreanddrizzle-ormas peer dependencies.
Quick Start
import { Box } from "boxfw-core";
import { D, createDbCtx } from "boxfw-db";
import { drizzle } from "drizzle-orm/bun-sqlite";
import Database from "bun:sqlite";
import * as schema from "./schema";
const sqlite = new Database("data.db");
const orm = drizzle(sqlite, { schema });
const app = new Box();
app.use(D(orm));
const db = createDbCtx<typeof orm>();
app.get("/users", async (c) => {
const rows = await db(c).select().from(schema.users);
return c.json(rows);
});Features
- Drizzle middleware — injects the ORM client into every request context via
D() - Unified migration runner —
migrate()dispatches to the correct Drizzle migrator based on driver - Per-request factories — create fresh clients per request (useful for D1 bindings)
- Driver support —
bun-sqlite,d1(Cloudflare),pg(PostgreSQL)
API
// Inject client as middleware
app.use(D(client));
// Inject factory (per-request)
app.use(D((c) => drizzle(c.env("DB"))));
// Migration (async, run at startup)
import { migrate } from "boxfw-db";
await migrate({ driver: "bun-sqlite", db: orm, migrationsFolder: "./drizzle" });License
MIT — see the LICENSE file for details.
