跳转到内容

CLI 快速开始

CLI 是试用 Graft 的最短路径。graft sql 打开普通物理 SQLite worktree 文件; repository command 直接调用 Graft control-plane service,不经过 SQLite extension 或 repository PRAGMA。

  1. 创建示例应用目录。

    Terminal window
    mkdir app-state-demo
    cd app-state-demo
  2. 初始化 Graft。

    Terminal window
    graft init

    这会创建 .graft/,但不会创建默认数据库。

  3. 写入 SQLite。

    Terminal window
    graft sql --db data.sqlite "CREATE TABLE notes(id INTEGER PRIMARY KEY, body TEXT);"
    graft sql --db data.sqlite "INSERT INTO notes(body) VALUES ('first note');"
  4. 查看状态。

    Terminal window
    graft status

    data.sqlite 仍是普通 SQLite 文件。repository command 需要检查或 stage 该 path 时,Graft 才读取它。

  5. 提交第一个应用状态版本。

    Terminal window
    graft add --all
    graft commit -m "seed notes"
  6. 修改数据库并添加文件。

    Terminal window
    graft sql --db data.sqlite "INSERT INTO notes(body) VALUES ('second note');"
    mkdir -p attachments
    printf 'draft\n' > attachments/readme.txt
  7. 查看路径分类。

    Terminal window
    graft status --json

    JSON 里的 path entry 会包含 kindstorage

  8. 提交并查看行级 diff。

    Terminal window
    graft add --all
    graft commit -m "add second note and attachment"
    graft diff --rows HEAD~1 HEAD data.sqlite
  9. 从最新 commit 恢复数据库。

    Terminal window
    graft sql --db data.sqlite "DELETE FROM notes;"
    graft restore --source HEAD -- data.sqlite
    graft status
Terminal window
cat <<'SQL' | graft sql --db data.sqlite
CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY, body TEXT);
INSERT INTO notes(body) VALUES ('hello from stdin');
SELECT * FROM notes;
SQL

branch 和 merge 命令会从当前目录发现仓库并操作整个 repository:

Terminal window
graft switch main
graft --db data.sqlite merge feature/search
graft merge --continue -m "merge feature/search"

switch 会直接 materialize 被跟踪的 worktree paths,不需要数据库选择器。需要 row-aware analysis 时,用 --dbmerge 打开对应 SQLite 数据库;完成 repository merge 时不再需要它。

下一步: