@velox/drizzle Stable
Drizzle ORM adapter for VeloxKit's built-in SQLite. Bridges Drizzle's sqlite-proxy driver to VeloxKit's native database bindings.
Requires capability: "db"
Install
npm install drizzle-orm @velox/drizzle
npm install -D drizzle-kitSetup
Open a database handle with db.open(), then pass it to createDrizzle:
// src/drizzle.ts
import { createDrizzle } from '@velox/drizzle'
import { db } from 'veloxkit'
import * as schema from './schema'
const handle = db.open()
export const drizzleDb = createDrizzle(handle, schema)API
createDrizzle(handle, schema?)
| Param | Type | Description |
|---|---|---|
handle | number | Database handle from db.open() |
schema | object | Optional Drizzle relational schema for .query.* API |
Returns a Drizzle SqliteRemoteDatabase — the full Drizzle query builder API.
Schema
// src/schema.ts
import { integer, text, sqliteTable } from 'drizzle-orm/sqlite-core'
export const notes = sqliteTable('notes', {
id: integer('id').primaryKey({ autoIncrement: true }),
title: text('title').notNull().default(''),
body: text('body').notNull().default(''),
pinned: integer('pinned', { mode: 'boolean' }).notNull().default(false),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
})Queries
import { drizzleDb } from './drizzle'
import { schema } from './schema'
import { desc, eq, like } from 'drizzle-orm'
// Select all
const allNotes = await drizzleDb.select().from(schema.notes).orderBy(desc(schema.notes.updatedAt))
// Select one
const note = await drizzleDb.select().from(schema.notes).where(eq(schema.notes.id, 42)).get()
// Insert
const [created] = await drizzleDb.insert(schema.notes)
.values({ title: 'Hello', createdAt: new Date(), updatedAt: new Date() })
.returning()
// Update
await drizzleDb.update(schema.notes)
.set({ title: 'Updated', updatedAt: new Date() })
.where(eq(schema.notes.id, 42))
// Delete
await drizzleDb.delete(schema.notes).where(eq(schema.notes.id, 42))
// Search
const results = await drizzleDb.select().from(schema.notes)
.where(like(schema.notes.title, '%hello%'))Migrations
Use db.migrate() for schema migrations — not Drizzle's migration runner (which requires a file system). Run migrations before calling createDrizzle:
import { db } from 'veloxkit'
import { createDrizzle } from '@velox/drizzle'
import * as schema from './schema'
db.migrate([
`CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL DEFAULT '',
body TEXT NOT NULL DEFAULT '',
pinned INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
)`,
])
const handle = db.open()
export const drizzleDb = createDrizzle(handle, schema)Notes
@velox/drizzleuses Drizzle'ssqlite-proxydriver internally — async queries only.- The
.query.*relational API is available if you passschematocreateDrizzle. - All queries go through VeloxKit's native SQLite binding — no Node.js
better-sqlite3required.