Rebase of PR #4601 (feat/choose-your-own-backend) onto current origin/main, squashed to a single commit because the original 73-commit history built and then removed the uowStore derisk spike incrementally, which does not replay cleanly over the 125 commits main has since advanced (notably #4679, the ready-work counts fix, which merged to main and is now inherited rather than re-applied). The full pre-rebase history remains on the original branch tip for reference. Contents (multi-backend feature + the six review follow-ups): - bd init --backend=postgres|mysql|sqlite provisioning behind the Dolt-parity seam; the three SQL backends share *sqlkit.Store over pluggable dialects and carry a generated typed-unsupported shell for the non-core surface. - Passwords in init DSNs are redacted before persisting to metadata.json (driver parser + re-parse verification), with a negative-test matrix proving no secret survives (pgdialect + mysql). - The uowStore derisk spike and its report artifacts are removed; the shell generator now lives in internal/storage/unsupportedgen (neutral name). - Compile-time guard `var _ storage.DoltStorage = (*Store)(nil)` on each backend plus a regen-idempotence test keep the generated skip lists honest. - sqlkit exposes CountReadyWork so every SQL backend satisfies storage.ReadyWorkCounter and inherits the shared page-pushed ready-counts path. - Commercial/product names scrubbed from the feature's own code for vendor neutrality. Rebase reconciliations: adopted main's metadata-load hardening in the store factories alongside the backend dispatch; combined the config interface (GetMetadata + ReconcileVersion) and the conformance registrations (ReadyCounts + Claim/lease); took main's versions of the shared-infra concurrency (uow doltserver_tx) and delete-cascade (domain/issue_delete) evolutions; implemented the interface's new UnclaimIssue on sqlkit (delegating to issueops) and added it to the skip lists. Verified: go build (cgo + CGO_ENABLED=0) and go vet clean; unit tests (sqlbuild/issueops/pgdialect/mysql/unsupportedgen) and the SQLite conformance suite green (RunAll, incl. ReadyCounts equivalence and Claim/lease on the real sqlkit backend). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package sqlitedialect
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
|
|
sqlite "modernc.org/sqlite"
|
|
)
|
|
|
|
// Open returns a *sql.DB over modernc.org/sqlite whose Prepare translates bd's
|
|
// canonical MySQL SQL to SQLite (see Translate). Like pgdialect it exposes no
|
|
// Execer/Queryer fast path, so database/sql routes every statement through Prepare.
|
|
// The caller supplies foreign-key enforcement etc. via DSN pragmas.
|
|
func Open(dsn string) (*sql.DB, error) {
|
|
return sql.OpenDB(&connector{dsn: dsn}), nil
|
|
}
|
|
|
|
// connector opens a fresh modernc connection per Connect. A zero-value
|
|
// modernc Driver carries no user-registered udfs/collations/hooks, which is exactly
|
|
// what the wedge wants; connection config travels in the DSN.
|
|
type connector struct{ dsn string }
|
|
|
|
func (c *connector) Connect(_ context.Context) (driver.Conn, error) {
|
|
base, err := (&sqlite.Driver{}).Open(c.dsn)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &conn{base: base}, nil
|
|
}
|
|
|
|
func (c *connector) Driver() driver.Driver { return &sqlite.Driver{} }
|
|
|
|
type conn struct{ base driver.Conn }
|
|
|
|
func (c *conn) Prepare(query string) (driver.Stmt, error) {
|
|
return c.base.Prepare(Translate(query))
|
|
}
|
|
|
|
func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
|
|
q := Translate(query)
|
|
if p, ok := c.base.(driver.ConnPrepareContext); ok {
|
|
return p.PrepareContext(ctx, q)
|
|
}
|
|
return c.base.Prepare(q)
|
|
}
|
|
|
|
func (c *conn) Close() error { return c.base.Close() }
|
|
|
|
//nolint:staticcheck // SA1019: driver.Conn requires the deprecated Begin; BeginTx forwarded below.
|
|
func (c *conn) Begin() (driver.Tx, error) { return c.base.Begin() }
|
|
|
|
func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
|
|
if b, ok := c.base.(driver.ConnBeginTx); ok {
|
|
return b.BeginTx(ctx, opts)
|
|
}
|
|
return c.base.Begin() //nolint:staticcheck
|
|
}
|
|
|
|
func (c *conn) ResetSession(ctx context.Context) error {
|
|
if rs, ok := c.base.(driver.SessionResetter); ok {
|
|
return rs.ResetSession(ctx)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *conn) IsValid() bool {
|
|
if v, ok := c.base.(driver.Validator); ok {
|
|
return v.IsValid()
|
|
}
|
|
return true
|
|
}
|