@boxdb/drizzle-adapter

中文文档
0.7.0发布于 2026/10/31MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 1750

Asynchronous Drizzle ORM adapter for BoxDB

原始使用文档

BoxDB adapter for Drizzle

An asynchronous SQLite driver for Drizzle 0.45.x. Install @boxdb/client, @boxdb/drizzle-adapter, and drizzle-orm.

npm install @boxdb/client @boxdb/drizzle-adapter drizzle-orm
import { BoxDB } from "@boxdb/client";
import { createDrizzleDatabase, migrate } from "@boxdb/drizzle-adapter";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";

const users = sqliteTable("users", {
  id: integer().primaryKey({ autoIncrement: true }).$type<bigint>(),
  name: text().notNull(),
});
await using client = await BoxDB.open("data.db");
const db = createDrizzleDatabase(client, { schema: { users } });
await migrate(db, { migrationsFolder: "./drizzle" });
const rows = await db.insert(users).values({ name: "Ada" }).returning();

The driver supports relational queries, joins, prepared Drizzle queries, RETURNING, and atomic batch. Drizzle transaction callbacks use BoxDB transaction handles internally; nested callbacks use savepoints. You can also pass an existing BoxDB transaction to createDrizzleDatabase.

Write metadata and integer cells remain bigint. Use integer().$type<bigint>() for Drizzle integer columns. Boolean columns map to boolean and timestamp columns map to Date, without converting unrelated integer cells. Migrations use an INTEGER journal and apply SQL and journal entries in one transaction.

The adapter borrows $client; close it yourself or use await using. For cancellation across Drizzle work, open a BoxDB transaction with a signal and create the Drizzle database from its handle. Base-client ownership rules apply when mixing Drizzle and direct SQL.

BoxDB columns

Declare extended types with the adapter's column builders:

import { decimal, instant, json, uuid } from "@boxdb/drizzle-adapter";

const invoices = sqliteTable("invoices", {
  id: uuid().primaryKey(),
  amount: decimal({ precision: 20, scale: 2 }).notNull(),
  createdAt: instant("created_at").notNull(),
  details: json().$type<{ reference: string }>(),
});

decimal, uuid, instant, date, time, dateTime and interval use strings for parameters and results. BoxDB validates and normalizes values in the declared SQL columns; exact decimals and temporal microseconds survive without conversion to JavaScript Number or Date. Builders expose the native SQL declarations for schema generation. time("opens") declares a TIME column, using values such as "09:30:00.000000" without a date or zone. Create matching columns through BoxDB migrations.

json serializes and parses complete documents in the client. $type<T>() describes the application type; it does not validate that shape at runtime. SQL NULL remains null. JSON/JSONB SQL inspection and editing are unsupported.

版本与发布记录

@boxdb/drizzle-adapter 共发布 15 个版本,首次发布于 2026/10/15;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/10/3110 天前
0.6.02026/10/3010 天前
0.5.12026/10/2417 天前
0.5.02026/10/2318 天前
0.4.32026/10/2218 天前
0.4.22026/10/1822 天前

关于 @boxdb/drizzle-adapter 的常见问题

@boxdb/drizzle-adapter 是什么?

Asynchronous Drizzle ORM adapter for BoxDB

如何安装 @boxdb/drizzle-adapter?

在项目目录运行 npm install @boxdb/drizzle-adapter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:drizzle-orm(^0.45.4)、@boxdb/client(^0.7.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@boxdb/drizzle-adapter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@boxdb/drizzle-adapter 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@boxdb/drizzle-adapter 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@boxdb/drizzle-adapter 可以商用吗?

@boxdb/drizzle-adapter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@boxdb/drizzle-adapter 的下载量有多少?

根据 npm 官方下载统计,@boxdb/drizzle-adapter 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,750 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@boxdb/drizzle-adapter 还在维护吗?

最新版本 0.7.0 发布于 2026/10/31(10 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/10/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。