npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@theokit/plugin-db-drizzle

v0.6.0

Published

Standalone DB plugin for TheoKit — wraps drizzle-kit + @theokit/orm with a plugin-shape factory, 7-verb theokit db CLI, drizzle-kit studio passthrough, and optional devtools tab integration. Form 4 Hybrid per plan p5-plugin-db-drizzle v1.0.

Readme

@theokit/plugin-db-drizzle

Standalone DB plugin for TheoKit — wraps drizzle-kit and @theokit/orm behind a single plugin-shape factory.

Status: v0.1.0 initial publish on the @next tag. Promote to @latest is calendar-gated alongside the Onda 2 cohort.

theokit db <verb> does not exist. This README promised seven CLI subcommands and a devtools tab for several releases; neither could ever run. register() wired them by calling app.registerCliCommand() / app.registerDevtoolsTab(), and the framework's TheoApp has only addHook and decorateRequest — the calls sat behind if (app.registerCliCommand) guards, so the result was a silent no-op rather than an error. The theokit CLI itself knows build, dev, doctor, start and has no plugin extension point. Tracked in #43; the command builders are still here and still tested, reachable now as exported functions (see § Migrations and studio).

What you get

  • One drizzleDb(opts) call, carrying resolved options your own tooling can read.
  • buildDbCommands(options) — the seven drizzle-kit invocations as data, to wire into a script of your own.
  • buildDevtoolsTab(options) — the studio-IFRAME tab descriptor, for whatever overlay you actually have.

@theokit/orm is a required peer — this plugin wraps it, never duplicates. Your Repository, @InjectRepository, @Transactional, and OrmModule keep working unchanged.

Install

pnpm add @theokit/plugin-db-drizzle@next @theokit/orm@next drizzle-orm reflect-metadata
# Optional — only needed for the CLI verbs (generate/migrate/studio/...)
pnpm add -D drizzle-kit

Wire it into theo.config.ts

import { drizzleDb } from '@theokit/plugin-db-drizzle'
import { config } from 'theokit'

export default config()
  .set({
    plugins: [
      drizzleDb({
        driver: 'postgres',
        url: process.env.DATABASE_URL,
        schemaPath: './db/schema.ts',
        migrationsPath: './db/migrations',
      }),
    ],
  })
  .build()

Options reference

| Option | Type | Default | Notes | | ---------------- | ----------------------------------- | ------------------- | ------------------------------------------------ | | driver | 'sqlite' \| 'postgres' \| 'mysql' | (required) | Canonical drizzle-kit driver names | | url | string | (caller-provided) | Connection URL — pass process.env.DATABASE_URL | | schemaPath | string | './db/schema.ts' | Path to your drizzle schema file | | migrationsPath | string | './db/migrations' | Directory for generated migration files | | devtoolsTab | boolean | true | Register a devtools-overlay tab when present |

Migrations and studio

There is no theokit db command to call (see the note at the top). What the package gives you is the seven drizzle-kit invocations as data, so you wire them where your project already keeps its scripts:

// scripts/db.ts
import { buildDbCommands, drizzleDb } from '@theokit/plugin-db-drizzle'
import { spawnSync } from 'node:child_process'

const plugin = drizzleDb({ driver: 'postgres', url: process.env.DATABASE_URL! })
const verb = process.argv[2]
const cmd = buildDbCommands(plugin.options).find((c) => c.verb === verb)
if (!cmd) throw new Error(`unknown verb ${verb}`)

// `buildArgs()` takes nothing: the options reached it through `buildDbCommands` above, and
// `plugin.options` is what fills the defaults it needs.
spawnSync('npx', ['drizzle-kit', ...cmd.buildArgs()], { stdio: 'inherit' })
{ "scripts": { "db": "tsx scripts/db.ts" } }
pnpm db generate    # migration from schema diff
pnpm db migrate     # apply pending migrations
pnpm db push        # push schema directly (dev-only)
pnpm db studio      # drizzle-kit studio (visual DB explorer)
pnpm db reset       # drop tables + re-apply all migrations
pnpm db seed        # run the user-provided seed script
pnpm db check       # check schema drift

Every verb shells out to drizzle-kit. Without it installed your runtime app still works — only these fail, with drizzle-kit's own message.

Devtools tab

buildDevtoolsTab(options) returns a { id, label, mount } descriptor that IFRAMEs http://localhost:4983 (drizzle-kit's default studio port). Mount it in whatever overlay you have:

import { buildDevtoolsTab, drizzleDb } from '@theokit/plugin-db-drizzle'

const tab = buildDevtoolsTab(drizzleDb({ driver: 'sqlite', url: ':memory:' }).options)
tab.mount(document.getElementById('panel')!)

The plugin does not register it for you — there is no framework hook to register it through (#43). drizzleDb({ devtoolsTab: false }) still resolves to false in options, so your own wiring can honour the flag.

RLS / auth integration

The plugin re-uses @theokit/orm's withAgentContext AsyncLocalStorage. Wrap session-scoped queries the same way you do with orm direct:

import { withAgentContext } from '@theokit/orm'

await withAgentContext({ agentId: session.agentId, conversationId }, async () => {
  return await users.findMany()
})

AgentContext carries agentId, runId and conversationId — all optional. It does not carry a user id: this context is what identifies the agent run, not the end user. For row-level security keyed to a user, put the user id where your own policy reads it; withAgentContext will not carry it for you.

For native RLS policy generation, drizzle-kit's RLS support is the canonical path — this plugin does not add a layer on top.

Migration from @theokit/orm direct usage

If you currently wire orm directly:

// Before
import { OrmModule } from '@theokit/orm'
defineConfig({
  modules: [OrmModule.forRoot({ connector: 'postgres', url: process.env.DATABASE_URL })],
})

// After
import { drizzleDb } from '@theokit/plugin-db-drizzle'
defineConfig({
  plugins: [drizzleDb({ driver: 'postgres', url: process.env.DATABASE_URL })],
})

Your Repository / decorator usage stays identical — the plugin re-exports orm's surface.

License

MIT