Database
Drizzle helpers: scoping, money, encryption, audit, plus plans, flags, analytics and more.
betaOn npm, API may still change
npm i @dapplelight/signet-db drizzle-ormQuick start
import { createDb } from "@dapplelight/signet-db/d1"
import { scoped } from "@dapplelight/signet-db"
import * as schema from "./schema"
import { userIdFrom } from "./auth"
export default {
async fetch(req: Request, bindings: { DB: D1Database }) {
const db = createDb(bindings.DB, { schema }) // per request, no env at import time
const me = scoped(db, { userId: await userIdFrom(req) })
return Response.json(await me.select(schema.orders)) // only this user's rows
},
}Core
Exported from @dapplelight/signet-db. The core never imports a driver.
| Export | What it does |
|---|---|
scoped(db, { userId }) | Per-user reads and writes; hides soft-deleted rows |
audited(db, { actor }) | Writes that leave an audit entry |
createCipher, generateKey | AES-GCM field encryption with key rotation |
moneyOf, addMoney, formatMoney | Integer minor-unit money |
newId, idTime | Sortable 26-char ids |
seed, exportUser, deleteUser | Seed rows, per-user export and erasure |
describeSchema, defineQuery, fromDrizzle | Schema text for agents, named queries, any Drizzle driver |
enqueue, drainOutbox, withIdempotency, dbCache, nextSequence | Outbox, idempotency keys, AI answer cache, sequences |
Modules
Admin
An admin API and admin tools generated from the schema.
Agent
Per-user database tools for AI agents.
AI Spend
Per-user, per-org and global AI spend caps.
Analytics
Events in your own database, with typed questions.
Charts
MRR, subscribers, churn and trials from the customer timeline.
Collab
Comments, mentions, activity and version history.
Columns
Column helpers and ready-made tables for SQLite, D1 and Postgres.
Customers
Customer timeline, identity merge and Customer Center.
D1
Cloudflare D1 driver.
Entitlements
Plans, features, usage limits and billing events.
Experiments
A/B/n tests with sticky assignment and significance.
Flags
Feature flags defined in code, overridable in the database.
Funnels
Web checkout funnels that unlock the purchase in the app.
Growth
Waitlist, invites, referrals, onboarding, changelog, feedback.
Import
Validated, chunked, idempotent bulk insert.
Migrations
Scan SQL migrations for data-losing changes.
Offerings
Versioned offerings and remote paywalls.
Orgs
Organisations, memberships, roles and permissions.
Postgres
Postgres driver on postgres-js.
Pricing
Pricing experiments across offerings.
Privacy
DPDP consent records and data requests.
SQLite
SQLite driver on bun:sqlite.
Status
Status page and maintenance switch.
Webhooks
Signed outbound webhooks with retries and a delivery log.
Workflows
Durable multi-step runs with approvals.
Zod
Zod schemas generated from table columns.