Skip to content

SQLite Extension

The SQLite extension is the main integration surface for applications. It registers a Graft VFS, stores SQLite pages in Graft storage, and exposes repository operations through PRAGMA graft_*.

In the SQLite shell:

.load ./libgraft_ext
.open "file:/path/to/project/app.db?vfs=graft"

Then initialize the project:

PRAGMA graft_init;

After initialization, repository data is stored under:

/path/to/project/.graft/
  1. Write normal SQLite data.

    CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT NOT NULL);
    INSERT INTO users(name) VALUES ('Alice');
  2. Inspect repository status.

    PRAGMA graft_status;
  3. Stage the current database snapshot.

    PRAGMA graft_add;
  4. Commit the staged snapshot.

    PRAGMA graft_commit = 'seed users';
  5. Compare revisions.

    PRAGMA graft_diff = 'HEAD~1 HEAD -- app.db';
    PRAGMA graft_json_diff = 'HEAD~1 HEAD -- app.db';

The database path is part of the repository identity. Opening /project/app.db through the Graft VFS makes app.db the worktree path for that database inside /project; the ordinary SQLite file only exists when you explicitly import or export one.

This is why repository mode no longer depends on environment variables for normal use. Configuration, refs, objects, and local storage live under .graft/.

A repository can track more than one SQLite database file:

project/
app.db
analytics.db
.graft/

Stage a specific database path:

PRAGMA graft_add = 'analytics.db';
PRAGMA graft_commit = 'track analytics database';

Any language that can execute SQLite SQL can call the same pragmas:

PRAGMA graft_status;
PRAGMA graft_add;
PRAGMA graft_commit = 'commit from app';