godolt
godolt wraps Dolt's operational surface for Go programs, following the gogit precedent — a standalone, dependency-light service-integration module.
Design: SQL-first. The primary workload is many concurrent sessions against dolt sql-server (the embedded driver sustains only one stable connection and is not a target), so version-control verbs run as Dolt stored procedures over the same MySQL wire as queries. The caller supplies the *sql.DB and godolt adds zero driver dependencies. The few operations that cannot run over the wire — clone/init bootstrap, server lifecycle, backups — shell out to the dolt CLI.
Library
- Client —
New(db *sql.DB)wraps an existing*sql.DBconnection to adolt sql-server; the caller owns the driver, pooling, and DSN. - Remotes —
Client.RemoteAdd,Client.RemoteRemove, andClient.Remotesregister, remove, and list configured remotes (CALL DOLT_REMOTE(...)). - Sync —
Client.PushandClient.Fetchpush/fetch against a remote (CALL DOLT_PUSH/DOLT_FETCH), returning the server's status message. Push is fast-forward-only; a diverged remote rejects it.Client.Pullfetches and merges a remote's branch (CALL DOLT_PULL), returning*PullResult(FastForward,Conflicts,Message) — a non-zeroConflictsmeans the merge completed but left conflict rows indolt_conflicts_<table>for the caller to resolve locally. - Branch —
Client.ActiveBranchreturns the connection's active branch (SELECT active_branch()). - Commits —
Client.HasUncommittedChanges,Client.AddAll,Client.Commit, andClient.CommitAllcheck the working set (dolt_status), stage everything (CALL DOLT_ADD('.')), and commit (CALL DOLT_COMMIT, returning the new hash).CommitAllis a no-op on a clean working set — the pattern applications use to wrap sync runs in Dolt commits. - Databases —
CreateDatabase(ctx, db, name)runsCREATE DATABASE IF NOT EXISTSover a server-wide connection (no database selected — seeSplitDSN). - DSN helpers —
LocalDSN,EnsureParseTime, andSplitDSNbuild the conventional local-server DSN, appendparseTime=truefor ORMs like Ent, and split a DSN into its server-wide base and database name. Pure string helpers — no driver dependency added. - Server lifecycle —
ServerReachable,StartServer, andEnsureServerprobe an address, launchdolt sql-serverover a data directory and wait for readiness (the caller owns the process), or ensure one is serving — launching it detached if not, the shared local-server pattern from visionstudio and omniroadmap. - Bootstrap —
Clone(ctx, remoteURL, dir)andInitDir(ctx, dir, name, email)are cold-path operations that shell out to thedoltCLI, since no server exists yet to talk to. - Availability —
Available()reports whether thedoltCLI is onPATH, the cold path's prerequisite. - Backups —
BackupAdd,BackupSync, andBackupRestoremanage named backup targets, snapshot/sync, and restore. NoDOLT_BACKUPstored procedure exists, so these are CLI-exec only — verified safe to run against a directory a livedolt sql-serveris actively serving.
db, _ := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/mydb")
client := godolt.New(db)
if err := client.RemoteAdd(ctx, "origin", "file:///path/to/remote"); err != nil {
log.Fatal(err)
}
msg, err := client.Push(ctx, "origin", "main")
Install:
go get github.com/grokify/godolt
See the README for full usage examples, and Releases for version history.