# @dolthub/doltlite 中文文档

规范地址：https://npmcn.com/package/%40dolthub/doltlite/

版本：0\.51\.11
npm 元数据更新时间：2026-11-12T00:35:28.321Z
中文译文更新时间：2026-11-12T15:20:44.376Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40dolthub/doltlite
原文对照：https://npmcn.com/package/%40dolthub/doltlite/?lang=original
项目主页：https://github.com/dolthub/doltlite-node#readme
源码仓库：https://github.com/dolthub/doltlite-node

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：41.8 MB，23 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.0\.0
- 运行依赖：1 个
- 首次发布：2026-05-07T23:17:48.658Z
- 最新版本发布：2026-11-12T00:35:28.086Z
- 近 30 天下载量：3547（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：72（近 12 个月 72 个）

## 中文简介

DoltLite 的节点.js绑定- 带有 Git 风格版本控制的 SQLite 叉

## 安装

```sh
npm install @dolthub/doltlite
```

也可以使用：`pnpm add @dolthub/doltlite`、`yarn add @dolthub/doltlite`、`bun add @dolthub/doltlite`

## README

# @dolthub/多尔特利特

节点.js 本地绑定 [点点数](https://github.com/dolthub/doltlite) —— SQLite分叉, 它将 Git 风格的版本控制( branches, confession, 合并, diffs, b责) 添加到您的 SQL 数据库中 .

[![CI](https://github.com/dolthub/doltlite-node/actions/workflows/ci.yml/badge.svg)](https://github.com/dolthub/doltlite-node/actions/workflows/ci.yml) [![npm](https://img.shields.io/npm/v/@dolthub/doltlite)](https://www.npmjs.com/package/@dolthub/doltlite)

## 安装

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

为Linux x64/arm64,macOS x64/arm64,和Windows x64提供预建二进制. 在不支持的平台上,软件包从源创建通过 `node-gyp`,它需要一个 C/C++ 工具链和 Python 3 .

## 滴入兼容性 `node:sqlite`

`DatabaseSync` 财务报告和审定财务报表 `StatementSync` 符合 [节点.js `node:sqlite`](https://nodejs.org/api/sqlite.html) API准确无误. 通过更改一个导入行切换 :

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

## 基本用途

```ts
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()
```

## 版本控制

所有 DOLT 特性都是方法 `DatabaseSync` 下级 `dolt*` 名称 :

```ts
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()
```

如果您喜欢,也可以直接调用 Dolt SQL 函数 :

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

## API 密码

### `new DatabaseSync(path, options?)`

| 选项 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| `open` | 布尔 | `true` | 立即打开 |
| `readOnly` | 布尔 | `false` | 只读模式 |

### 节点: sqlite 兼容方法

| 方法 | 说明 |
| --- | --- |
| `exec(sql)` | 运行 SQL, 无返回值 |
| `prepare(sql)` | 编译 a `StatementSync` |
| `close()` | 关闭连接 |
| `open(path)` | (重) 打开路径 |
| `location()` | 文件系统路径, 或 `null` 页:1 `:memory:` |
| `createFunction(name, fn)` | 注册一个 Scalar UDF |
| `.isOpen` | `true` 如果连接已打开 |
| `.inTransaction` | `true` 如果交易内部 |

### 语句同步

| 方法 | 回返 |
| --- | --- |
| `run(...params)` | `{ changes, lastInsertRowid }` |
| `get(...params)` | 第一行对象,或 `undefined` |
| `all(...params)` | 所有行对象 |
| `iterate(...params)` | `IterableIterator` |
| `columns()` | 列元数据数组 |
| `.sourceSQL` | 原始 SQL 文本 |
| `.expandedSQL` | 扩大参数的 SQL |

### 玩偶方法

| 方法 | 回返 | 说明 |
| --- | --- | --- |
| `doltCommit(message)` | `string` (哈什语) | 完成所有任务 |
| `doltBranch(name, from?)` | `void` | 创建分支 |
| `doltCheckout(branch)` | `void` | 切换分支 |
| `doltMerge(branch)` | `{ fast_forward, conflicts }` | 合并分支 |
| `doltReset(flag?)` | `void` | 重置头; 通过 `"--hard"` 用于硬重置 |
| `doltAdd(table?)` | `void` | 阶段一个表格, 或所有表格 |
| `doltStatus()` | `DoltStatusEntry[]` | 工作状况 |
| `doltLog(opts?)` | `DoltCommit[]` | 提交历史, 最新的第一 |
| `doltBranches()` | `DoltBranchInfo[]` | 所有分支 |
| `doltActiveBranch()` | `string` | 当前退出分支 |
| `doltDiff(from, to, table)` | `DoltDiffRow[]` | 两个裁判之间的行级diff |
| `doltHashOf(ref?)` | `string` | 数据库内容散列 |
| `doltVersion()` | `string` | DoltLite 版本字符串 |
| `doltTag(name)` | `void` | 在头部创建标签 |
| `doltTags()` | `DoltTagInfo[]` | 所有标签 |
| `doltHistoryOf(table)` | `object[]` | 横跨全行历史 |
| `doltBlameOf(table)` | `object[]` | 每行人的责任 |
| `doltCherryPick(hash)` | `void` | 樱桃选一个承诺到头 |
| `doltRevert(ref?)` | `void` | 还原一个承诺( 默认: HEAD) |

### `binPath()`

返回捆绑的绝对路径 `doltlite` 当前平台的 CLI 二进制 。 消费者希望直接产出外壳时有用,例如用于交互 `db` 子命令——而不是通过节点绑定来驱动一切.

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

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

如果没有为当前平台/ arch 捆绑 CLI 构建则丢弃 。 (目前是用于 `linux-x64`, (中文(简体) ), `darwin-arm64`,以及 `win32-x64`; 数据 `.node` 加通覆盖的平台比外壳多. )

## 从源头建楼

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

**所需经费:** Python 3 和一个 C/C++ 编译器(`gcc`编号 :`clang` 在Linux/macOS上,MSVC在Windows上构建工具).

## 版本

软件包版本跟踪了多尔特Lite版本. `@dolthub/doltlite@0.11.8` doltLite 0.11.8 并联号.

## 许可证

阿帕奇2.0 (英语). 见 [点点数](https://github.com/dolthub/doltlite) 用于基础图书馆.

## 常见问题

### @dolthub/doltlite 是什么？

DoltLite 的节点\.js绑定- 带有 Git 风格版本控制的 SQLite 叉

### 如何安装 @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 和提交记录判断。

