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 ¶
- func Available() bool
- func BackupAdd(ctx context.Context, dir, name, url string) error
- func BackupRestore(ctx context.Context, workDir, url, dbName string, force bool) error
- func BackupSync(ctx context.Context, dir, name string) error
- func Clone(ctx context.Context, remoteURL, dir string) error
- func CreateDatabase(ctx context.Context, db *sql.DB, name string) error
- func EnsureParseTime(dsn string) string
- func EnsureServer(dataDir string, port int) error
- func InitDir(ctx context.Context, dir, name, email string) error
- func LocalDSN(port int, database string) string
- func ServerReachable(addr string) bool
- func SplitDSN(dsn string) (base string, database string, err error)
- func StartServer(dataDir string, port int) (*exec.Cmd, error)
- type Client
- func (c *Client) ActiveBranch(ctx context.Context) (string, error)
- func (c *Client) AddAll(ctx context.Context) error
- func (c *Client) Commit(ctx context.Context, message string) (hash string, err error)
- func (c *Client) CommitAll(ctx context.Context, message string) (hash string, err error)
- func (c *Client) Fetch(ctx context.Context, remote string) error
- func (c *Client) HasUncommittedChanges(ctx context.Context) (bool, error)
- func (c *Client) Pull(ctx context.Context, remote, branch string) (*PullResult, error)
- func (c *Client) Push(ctx context.Context, remote, branch string) (string, error)
- func (c *Client) RemoteAdd(ctx context.Context, name, url string) error
- func (c *Client) RemoteRemove(ctx context.Context, name string) error
- func (c *Client) Remotes(ctx context.Context) ([]Remote, error)
- type PullResult
- type Remote
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 BackupRestore ¶
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 ¶
BackupSync snapshots the Dolt database in dir (branches, tags, working sets) and uploads it to the named backup target.
func CreateDatabase ¶ added in v0.3.0
CreateDatabase creates the named database if it does not exist. The caller supplies a *sql.DB connected server-wide (no database selected — see SplitDSN); godolt adds no driver dependency.
func EnsureParseTime ¶ added in v0.3.0
EnsureParseTime appends parseTime=true to a MySQL DSN if absent. ORMs such as Ent need it to scan DATETIME columns into time.Time.
func EnsureServer ¶ added in v0.3.0
EnsureServer checks that a dolt sql-server is reachable on 127.0.0.1:port, launching one as a detached subprocess over dataDir if not. The launched process keeps serving after the caller exits — suitable for local developer tools that share one long-lived server (the visionstudio/omniroadmap pattern).
func LocalDSN ¶ added in v0.3.0
LocalDSN returns the conventional DSN for a local dolt sql-server: root with no password on 127.0.0.1.
func ServerReachable ¶ added in v0.3.0
ServerReachable reports whether a TCP listener answers on addr (host:port) within 500ms.
func SplitDSN ¶ added in v0.3.0
SplitDSN splits a go-sql-driver DSN into the DSN without a database selected (still carrying any query parameters) and the database name. Use it to connect server-wide before the target database exists.
func StartServer ¶ added in v0.3.0
StartServer launches `dolt sql-server` over dataDir on 127.0.0.1:port, creating dataDir if needed, and waits until the server accepts connections. The caller owns the returned process: Wait on it, kill it, or detach. Requires the dolt binary on PATH.
Types ¶
type Client ¶
Client executes Dolt operations over an existing SQL connection to a dolt sql-server. The caller owns the *sql.DB (driver, pooling, DSN).
func (*Client) ActiveBranch ¶
ActiveBranch returns the connection's active branch.
func (*Client) Commit ¶ added in v0.3.0
Commit commits staged changes (CALL DOLT_COMMIT('-m', message)) and returns the new commit hash. The message is passed as a bind parameter, so it may contain any characters. Committing with nothing staged returns an error from Dolt; use CommitAll for no-op-when-clean semantics.
func (*Client) CommitAll ¶ added in v0.3.0
CommitAll stages and commits all changes with the given message, returning the new commit hash. A clean working set is a no-op returning ("", nil) — the pattern applications use to wrap sync runs in Dolt commits.
func (*Client) HasUncommittedChanges ¶ added in v0.3.0
HasUncommittedChanges reports whether the working set has staged or unstaged changes (any rows in dolt_status).
func (*Client) Pull ¶
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 ¶
Push pushes branch to remote (CALL DOLT_PUSH). Returns the server message (e.g. "Everything up-to-date").
func (*Client) RemoteRemove ¶
RemoteRemove removes a remote.
type PullResult ¶ added in v0.2.0
PullResult reports the outcome of a CALL DOLT_PULL.