跳转到内容

导出 SQLite 文件

Graft 把 SQLite 历史存为 snapshot,但可以 materialize 和 export 普通 SQLite 数据库文件。

默认情况下,commit、checkout、switch、pull 和 merge-continue 后,Graft 会把 tracked SQLite snapshot 写回 worktree 的数据库路径:

project/
data.sqlite
.graft/

data.sqlite 是普通 SQLite 文件,可被标准工具读取。

导出当前 worktree database state:

Terminal window
graft export --output data.inspect.sqlite data.sqlite

导出指定 revision:

Terminal window
graft export --source HEAD --output data.head.sqlite data.sqlite
graft export --source HEAD~1 --output data.previous.sqlite data.sqlite

导出的文件是普通 SQLite 数据库,不再连接当前 Graft volume。

普通 SQLite 连接是默认写入方式。提交 SQLite transaction 后直接 stage:

Terminal window
sqlite3 data.sqlite "INSERT INTO notes(body) VALUES ('external edit');"
graft add data.sqlite
graft commit -m "import external edit"

graft add 使用 SQLite online backup 捕获一致的 committed state,包括已提交的 WAL frames,不需要手动 checkpoint,也不会修改源数据库。随后它只把相对 staged/HEAD 基线发生变化的 4 KiB Graft storage chunks 写入存储,这个粒度与物理 数据库的 SQLite page size 无关。

需要 live page-storage 时可以显式选择 vfs=graft,但它是可选数据面,不承载 repository 命令。

[worktree]
materialize_sqlite = true

默认是 true。只有明确想要 volume-only database path 的集成才应设为 false