godolt

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 5 Imported by: 0

README

godolt

Go CI Go Lint Go SAST Docs Docs Visualization License

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 — remotes, push, pull, fetch, active branch — 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.

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")

Library Features

Feature Entry Point Description
Client New(db *sql.DB) Wraps an existing *sql.DB connection to a dolt sql-server; the caller owns the driver, pooling, and DSN
Remotes Client.RemoteAdd, Client.RemoteRemove, Client.Remotes Register, remove, and list configured remotes (CALL DOLT_REMOTE(...))
Sync Client.Push, Client.Fetch Push/fetch against a remote (CALL DOLT_PUSH/DOLT_FETCH), returning the server's status message
Sync Client.Pull Pull and merge a remote's branch (CALL DOLT_PULL); returns *PullResult (FastForward, Conflicts, Message) — a non-zero Conflicts means the merge completed but left conflict rows in dolt_conflicts_<table> for the caller to resolve
Branch Client.ActiveBranch The connection's active branch (SELECT active_branch())
Bootstrap Clone(ctx, remoteURL, dir), InitDir(ctx, dir, name, email) Cold-path operations that shell out to the dolt CLI, since no server exists yet to talk to
Availability Available() Reports whether the dolt CLI is on PATH — the cold path's prerequisite
Backups BackupAdd, BackupSync, BackupRestore Named backup targets, snapshot/sync, and restore — no DOLT_BACKUP stored procedure exists, so these are CLI-exec only. Verified safe to run against a directory a live dolt sql-server is actively serving

Installation

go get github.com/grokify/godolt

Usage

SQL-wire operations (the primary workload)
import (
	"context"
	"database/sql"

	"github.com/grokify/godolt"
	_ "github.com/go-sql-driver/mysql"
)

db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/mydb")
if err != nil {
	log.Fatal(err)
}
client := godolt.New(db)

ctx := context.Background()
if err := client.RemoteAdd(ctx, "origin", "file:///path/to/remote"); err != nil {
	log.Fatal(err)
}

remotes, err := client.Remotes(ctx)

msg, err := client.Push(ctx, "origin", "main")

// Push is fast-forward-only: a remote with commits the local branch
// doesn't have rejects the push (error contains "non-fast-forward").
// Pull to fetch and merge before pushing again.
result, err := client.Pull(ctx, "origin", "main")
if result.Conflicts > 0 {
	// Merge completed; resolve dolt_conflicts_<table> rows before pushing.
}

branch, err := client.ActiveBranch(ctx)
Cold path: bootstrap and backups
if !godolt.Available() {
	log.Fatal("dolt CLI not found on PATH")
}

if err := godolt.InitDir(ctx, "/path/to/db", "my-service", "my-service@local"); err != nil {
	log.Fatal(err)
}

if err := godolt.Clone(ctx, "file:///path/to/remote", "/path/to/clone"); err != nil {
	log.Fatal(err)
}

if err := godolt.BackupAdd(ctx, "/path/to/db", "spike", "file:///path/to/backup"); err != nil {
	log.Fatal(err)
}
if err := godolt.BackupSync(ctx, "/path/to/db", "spike"); err != nil {
	log.Fatal(err)
}

Documentation

Full docs, including release notes, are published at grokify.github.io/godolt.

License

MIT

Documentation

Overview

Package godolt wraps Dolt's operational surface for Go programs, following the gogit precedent (a standalone 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) shell out to the dolt CLI (exec.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available reports whether the dolt CLI is on PATH (the cold path's prerequisite; the SQL path needs only a *sql.DB).

func BackupAdd

func BackupAdd(ctx context.Context, dir, name, url string) error

BackupAdd registers a named backup target for the Dolt database in dir.

func BackupRestore

func BackupRestore(ctx context.Context, workDir, url, dbName string, force bool) error

BackupRestore restores a database from a backup URL into a new subdirectory named dbName under workDir (workDir must not already contain a directory of that name unless force is set).

func BackupSync

func BackupSync(ctx context.Context, dir, name string) error

BackupSync snapshots the Dolt database in dir (branches, tags, working sets) and uploads it to the named backup target.

func Clone

func Clone(ctx context.Context, remoteURL, dir string) error

Clone clones a remote URL into dir (dir must not already contain a Dolt repository).

func InitDir

func InitDir(ctx context.Context, dir, name, email string) error

InitDir initializes a new Dolt database directory with the given committer identity.

Types

type Client

type Client struct {
	DB *sql.DB
}

Client executes Dolt operations over an existing SQL connection to a dolt sql-server. The caller owns the *sql.DB (driver, pooling, DSN).

func New

func New(db *sql.DB) *Client

New returns a Client over db.

func (*Client) ActiveBranch

func (c *Client) ActiveBranch(ctx context.Context) (string, error)

ActiveBranch returns the connection's active branch.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, remote string) error

Fetch fetches from remote (CALL DOLT_FETCH).

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, remote, branch string) (*PullResult, error)

Pull pulls branch from remote (CALL DOLT_PULL) and merges into the active branch. DOLT_PULL returns three columns (fast_forward, conflicts, message) — a different shape from every other stored procedure call() handles, so Pull scans it directly rather than going through call(). A non-zero Conflicts count means DOLT_PULL completed the merge but left conflict rows in dolt_conflicts_<table> for the caller to resolve; it is not returned as an error, since that is expected, resolvable local state, not a failure of the pull itself.

func (*Client) Push

func (c *Client) Push(ctx context.Context, remote, branch string) (string, error)

Push pushes branch to remote (CALL DOLT_PUSH). Returns the server message (e.g. "Everything up-to-date").

func (*Client) RemoteAdd

func (c *Client) RemoteAdd(ctx context.Context, name, url string) error

RemoteAdd registers a remote (CALL DOLT_REMOTE('add', name, url)).

func (*Client) RemoteRemove

func (c *Client) RemoteRemove(ctx context.Context, name string) error

RemoteRemove removes a remote.

func (*Client) Remotes

func (c *Client) Remotes(ctx context.Context) ([]Remote, error)

Remotes lists configured remotes from the dolt_remotes system table.

type PullResult added in v0.2.0

type PullResult struct {
	FastForward bool
	Conflicts   int
	Message     string
}

PullResult reports the outcome of a CALL DOLT_PULL.

type Remote

type Remote struct {
	Name string
	URL  string
}

Remote is a configured Dolt remote.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL