Drizzle ORM
Drizzle ORM
Section titled “Drizzle ORM”Drizzle ORM is a TypeScript-first SQL toolkit — a
thin, fully typed layer over Postgres with no code-generation step. The adapter
ships three pieces on katanakit-js/adapters/drizzle:
useDrizzleClient()— a lazy singleton client over the node-postgres driver (pg);DATABASE_URLis read on first call, never at import.conversations/messages—pgTabledefinitions shaped after the Prisma contract, so both integrations describe the same database and you can switch without a migration.useCreateDrizzleStore()/DrizzleConversationStore— aConversationStorefor the assistant, so history survives restarts.
Install
Section titled “Install”bun add drizzle-orm pgbun add -D drizzle-kit # migrations and studiodrizzle-orm and pg are optional peer dependencies — only imported when
you use the subpath.
Client
Section titled “Client”import { conversations, useDrizzleClient } from "katanakit-js/adapters/drizzle";
const db = useDrizzleClient(); // DATABASE_URL from the environmentconst rows = await db.select().from(conversations).limit(5);DATABASE_URL must be in the process environment — the package never loads
.env itself (Bun reads it automatically; on Node use node --env-file=.env).
Pass a URL explicitly for tests: useDrizzleClient("postgresql://…").
Tables and migrations
Section titled “Tables and migrations”The conversations and messages tables (Prisma-shaped: camelCase columns,
uuid/serial primary keys, cascade deletes) are exported from the same subpath,
so your own queries are fully typed. Push them with drizzle-kit push, or
generate SQL migrations with drizzle-kit generate from a drizzle.config.ts
that points at your schema re-exports.
Assistant persistence
Section titled “Assistant persistence”import { useInitAssistant } from "katanakit-js";import { DrizzleConversationStore, useCreateDrizzleStore,} from "katanakit-js/adapters/drizzle";
useInitAssistant({ store: useCreateDrizzleStore() });// or: { store: DrizzleConversationStore }The store implements the same ConversationStore contract
as the in-memory and Prisma stores: the client stays lazy and DATABASE_URL
errors surface on first use, not at import.
Example
Section titled “Example”examples/drizzle/
shows the lazy query helper and the assistant wiring.