@dolthub/多尔特利特
节点.js 本地绑定 点点数 —— SQLite分叉, 它将 Git 风格的版本控制( branches, confession, 合并, diffs, b责) 添加到您的 SQL 数据库中 .
安装
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 API准确无误. 通过更改一个导入行切换 :
-import { DatabaseSync } from "node:sqlite"
+import { DatabaseSync } from "@dolthub/doltlite"
基本用途
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* 名称 :
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 函数 :
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 子命令——而不是通过节点绑定来驱动一切.
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 加通覆盖的平台比外壳多. )
从源头建楼
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/[email protected] doltLite 0.11.8 并联号.
许可证
阿帕奇2.0 (英语). 见 点点数 用于基础图书馆.