CLI Quickstart
The graft CLI is a convenience wrapper around repository-mode SQLite pragmas. It also includes an embedded SQLite runner:
graft sql "SELECT 1;"That command opens app.db through the embedded Graft VFS. You do not need to load libgraft_ext manually.
Build The CLI
Section titled “Build The CLI”From the repository root:
cargo build -p graft-tool --bin graft --releaseThe binary is written to:
target/release/graftAdd it to your PATH however you prefer. For example:
mkdir -p ~/.local/binln -sf "$(pwd)/target/release/graft" ~/.local/bin/grafthash -rgraft --helpCreate A Project
Section titled “Create A Project”-
Create a project directory.
Terminal window mkdir graft-democd graft-demo -
Initialize the repository.
Terminal window graft initThis creates
.graft/next toapp.db. -
Create and query data.
Terminal window graft sql "CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT);"graft sql "INSERT INTO users(name) VALUES ('Alice'); SELECT * FROM users;" -
Check status.
Terminal window graft statusYou should see
untracked: app.db. -
Stage and commit.
Terminal window graft add app.dbgraft commit -m "seed users" -
Modify the database again.
Terminal window graft sql "INSERT INTO users(name) VALUES ('Bob'); SELECT * FROM users ORDER BY id;"graft statusYou should see
modified: app.db. -
Commit the second snapshot and diff it.
Terminal window graft add app.dbgraft commit -m "add bob"graft diff HEAD~1 HEAD app.db
Running SQL From Stdin
Section titled “Running SQL From Stdin”If no SQL argument is passed, graft sql reads stdin:
cat <<'SQL' | graft sqlCREATE TABLE notes(id INTEGER PRIMARY KEY, body TEXT);INSERT INTO notes(body) VALUES ('hello from stdin');SELECT * FROM notes;SQLOne-Command Initialization
Section titled “One-Command Initialization”For scripts, you can initialize and write data in a single batch:
cat <<'SQL' | graft sqlPRAGMA graft_init;CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT);INSERT INTO users(name) VALUES ('Alice');SELECT * FROM users;SQLWhat The CLI Does Internally
Section titled “What The CLI Does Internally”Most commands map directly to repository pragmas:
graft status -> PRAGMA graft_statusgraft add app.db -> PRAGMA graft_add = 'app.db'graft commit -m "msg" -> PRAGMA graft_commit = 'msg'graft diff HEAD~1 HEAD -> PRAGMA graft_diff = 'HEAD~1 HEAD'That means the CLI and extension share the same semantics. The CLI should not grow a separate repository model.