@dolthub/doltlite

中文文档
0.51.11发布于 2026/11/12Apache-2.0TypeScriptCommonJS近 30 天下载 3547

Node.js bindings for DoltLite — a SQLite fork with Git-style version control

原始使用文档
文档目录13 节
  1. Install
  2. Drop-in compatibility with node:sqlite
  3. Basic usage
  4. Version control
  5. API
  6. new DatabaseSync(path, options?)
  7. node:sqlite-compatible methods
  8. StatementSync
  9. Dolt methods
  10. binPath()
  11. Building from source
  12. Versioning
  13. License

@dolthub/doltlite

Node.js native bindings for DoltLite — a SQLite fork that adds Git-style version control (branches, commits, merges, diffs, blame) to your SQL database.

CI npm

Install

npm install @dolthub/doltlite
# or
bun add @dolthub/doltlite

Prebuilt binaries are provided for Linux x64/arm64, macOS x64/arm64, and Windows x64. On unsupported platforms the package builds from source via node-gyp, which requires a C/C++ toolchain and Python 3.

Drop-in compatibility with node:sqlite

DatabaseSync and StatementSync match the Node.js node:sqlite API exactly. Switch by changing one import line:

-import { DatabaseSync } from "node:sqlite"
+import { DatabaseSync } from "@dolthub/doltlite"

Basic usage

import { DatabaseSync } from "@dolthub/doltlite"

const db = new DatabaseSync("myapp.db")

db.exec(`CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)`)

const insert = db.prepare("INSERT INTO users (name) VALUES (?)")
insert.run("Alice")
insert.run("Bob")

const all = db.prepare("SELECT * FROM users")
console.log(all.all())
// [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]

db.close()

Version control

All Dolt features are methods on DatabaseSync under dolt* names:

const db = new DatabaseSync("versioned.db")

db.exec(`CREATE TABLE orders (id INTEGER PRIMARY KEY, amount REAL)`)
db.exec(`INSERT INTO orders VALUES (1, 99.99)`)

// Commit the current state
const hash = db.doltCommit("initial data")

// Branch and make changes
db.doltBranch("experiment")
db.doltCheckout("experiment")
db.exec(`INSERT INTO orders VALUES (2, 49.99)`)
db.doltCommit("add order 2")

// See what changed
console.log(db.doltStatus())
console.log(db.doltLog({ limit: 5 }))

// Merge back to main
db.doltCheckout("main")
const result = db.doltMerge("experiment")
console.log(result) // { fast_forward: 0, conflicts: 0 }

// Inspect history
console.log(db.doltDiff("HEAD~1", "HEAD", "orders"))
console.log(db.doltHistoryOf("orders"))
console.log(db.doltBlameOf("orders"))

// Tag a release
db.doltTag("v1.0.0")

db.close()

You can also call Dolt SQL functions directly if you prefer:

db.exec("SELECT dolt_commit('-Am', 'my message')")

API

new DatabaseSync(path, options?)

OptionTypeDefaultDescription
openbooleantrueOpen immediately
readOnlybooleanfalseRead-only mode

node:sqlite-compatible methods

MethodDescription
exec(sql)Run SQL, no return value
prepare(sql)Compile a StatementSync
close()Close the connection
open(path)(Re-)open at path
location()Filesystem path, or null for :memory:
createFunction(name, fn)Register a scalar UDF
.isOpentrue if connection is open
.inTransactiontrue if inside a transaction

StatementSync

MethodReturns
run(...params){ changes, lastInsertRowid }
get(...params)First row object, or undefined
all(...params)All row objects
iterate(...params)IterableIterator
columns()Column metadata array
.sourceSQLOriginal SQL text
.expandedSQLSQL with parameters expanded

Dolt methods

MethodReturnsDescription
doltCommit(message)string (hash)Stage all and commit
doltBranch(name, from?)voidCreate a branch
doltCheckout(branch)voidSwitch branch
doltMerge(branch){ fast_forward, conflicts }Merge a branch
doltReset(flag?)voidReset HEAD; pass "--hard" for hard reset
doltAdd(table?)voidStage a table, or all tables
doltStatus()DoltStatusEntry[]Working-set status
doltLog(opts?)DoltCommit[]Commit history, newest first
doltBranches()DoltBranchInfo[]All branches
doltActiveBranch()stringCurrently checked-out branch
doltDiff(from, to, table)DoltDiffRow[]Row-level diff between two refs
doltHashOf(ref?)stringContent hash of the DB at a ref
doltVersion()stringDoltLite version string
doltTag(name)voidCreate a tag at HEAD
doltTags()DoltTagInfo[]All tags
doltHistoryOf(table)object[]Full row history across all commits
doltBlameOf(table)object[]Per-row blame
doltCherryPick(hash)voidCherry-pick a commit onto HEAD
doltRevert(ref?)voidRevert a commit (default: HEAD)

binPath()

Returns the absolute path to the bundled doltlite CLI binary for the current platform. Useful when a consumer wants to spawn the shell directly — e.g. for an interactive db subcommand — rather than driving everything through the Node bindings.

import { binPath } from "@dolthub/doltlite"
import { spawn } from "child_process"

const child = spawn(binPath(), ["mydata.db"], { stdio: "inherit" })

Throws if no CLI build is bundled for the current platform/arch. (Upstream currently ships CLI tools for linux-x64, darwin-arm64, and win32-x64; the .node addon covers more platforms than the shell.)

Building from source

git clone https://github.com/dolthub/doltlite-node
cd doltlite-node
npm install   # downloads amalgamation + compiles
bun test      # run the test suite

Requirements: Python 3, and a C/C++ compiler (gcc/clang on Linux/macOS, MSVC Build Tools on Windows).

Versioning

The package version tracks the DoltLite version. @dolthub/[email protected] ships the DoltLite 0.11.8 amalgamation.

License

Apache-2.0. See DoltLite for the underlying library.

版本与发布记录

@dolthub/doltlite 共发布 72 个版本,首次发布于 2026/05/08;过去 12 个月发布了 72 个版本。

版本发布日期距今
0.51.11latest2026/11/121 天前
0.51.102026/11/094 天前
0.51.92026/11/067 天前
0.51.82026/11/058 天前
0.51.72026/11/049 天前
0.51.62026/11/0211 天前

关于 @dolthub/doltlite 的常见问题

@dolthub/doltlite 是什么?

Node.js bindings for DoltLite — a SQLite fork with Git-style version control

如何安装 @dolthub/doltlite?

在项目目录运行 npm install @dolthub/doltlite,或使用 pnpm add / yarn add / bun add。

@dolthub/doltlite 支持 TypeScript 吗?

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

@dolthub/doltlite 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dolthub/doltlite 需要什么版本的 Node.js?

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

@dolthub/doltlite 可以商用吗?

@dolthub/doltlite 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dolthub/doltlite 的下载量有多少?

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

@dolthub/doltlite 还在维护吗?

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