Documentation
¶
Overview ¶
Package cli implements the sqletch commands as testable functions; cmd/sqletch is thin cobra wiring over these. The pipeline here is the cache-aware flow of docs/design/04-type-oracle.md §4.
Index ¶
- Constants
- func Check(ctx context.Context, configPath string, exhaustive, jsonFormat bool, ...) int
- func Explain(ctx context.Context, configPath string, queryNames []string, ...) int
- func Fmt(configPath string, check bool, out, errW io.Writer) int
- func Generate(ctx context.Context, configPath string, jsonFormat bool, opts RunOptions, ...) int
- func LSP(configPath string, in io.Reader, out, errW io.Writer) int
- func PrintDiags(w io.Writer, res *Result, jsonFormat bool)
- type ExplainOptions
- type Mode
- type OfflineChecker
- type Result
- type RunOptions
- type WorkspaceCheck
Constants ¶
const ( ExitOK = 0 ExitDiagnostics = 1 ExitEnvironment = 2 )
Exit codes (design 07 §2): 0 ok, 1 diagnostics, 2 environment.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(ctx context.Context, configPath string, exhaustive, jsonFormat bool, opts RunOptions, out, errW io.Writer) int
Check implements `sqletch check [--exhaustive]`.
func Explain ¶
func Explain(ctx context.Context, configPath string, queryNames []string, opts ExplainOptions, out, errW io.Writer) int
Explain implements `sqletch explain [query…]` from the data written at generate time — no database, no recompilation. With enumerate, it prints every reachable shape's SQL instead (scan + render only, still no database).
func Fmt ¶
Fmt implements `sqletch fmt [--check]`: canonicalize template files in place, or report the ones that would change.
func Generate ¶
func Generate(ctx context.Context, configPath string, jsonFormat bool, opts RunOptions, out, errW io.Writer) int
Generate implements `sqletch generate`.
Types ¶
type ExplainOptions ¶
type ExplainOptions struct {
Enumerate bool // print every reachable shape's SQL (offline)
Analyze bool // EXPLAIN every reachable shape on the dev DB
// MaxShapes caps shape enumeration for Enumerate/Analyze; 0 takes
// the mode's default (enumerateCap / analyzeCap).
MaxShapes int
// AllowDestructive confirms a user-supplied database.dsn is
// disposable so --analyze may reset its schema (H1); ignored by the
// offline modes, which never connect.
AllowDestructive bool
}
ExplainOptions carries the `sqletch explain` flags.
type OfflineChecker ¶
type OfflineChecker struct {
// contains filtered or unexported fields
}
OfflineChecker is the LSP-facing slice of the pipeline (docs/design/10-lsp.md §4): scan + lexical + R1 per file, memoized by content hash; duplicate-name detection across the workspace; and the catalog-dependent pass for exactly those queries whose catalog and renderings are all present in the committed cache. It NEVER opens a database connection.
func NewOfflineChecker ¶
func NewOfflineChecker(cfg config.Config) *OfflineChecker
func (*OfflineChecker) Check ¶
func (c *OfflineChecker) Check(overlay map[string][]byte) (WorkspaceCheck, error)
Check analyzes the workspace with overlay contents (open editor buffers) replacing disk. It degrades rather than failing: an unreadable glob-matched file becomes a per-file diagnostic (CodeSourceUnreadable) and the rest of the workspace still checks, so the error return is retained only for the interface and is currently always nil. User mistakes are diagnostics.
type Result ¶
type Result struct {
Diags []diagnostics.Diagnostic
Sources map[string][]byte // template path -> content (for rendering diags)
OracleHits int
OracleMiss int
Offline bool
QueryCount int
ShapesTotal int // exhaustive mode: shapes verified against the DB
// NativePlan: exhaustive mode ran on the native backend, whose
// Plan is describe-validation only — the printed summary must not
// claim EXPLAIN coverage (design 15 D2).
NativePlan bool
}
Result carries what the commands report to the user.
type RunOptions ¶
type RunOptions struct {
// AllowServerDrift accepts a committed cache whose recorded
// generation environment disagrees with the connected server,
// downgrading SQLETCH203 to a warning and adopting the connected
// server in the record. The result is a cache no single
// environment produced — deliberate, and never the default.
AllowServerDrift bool
// AllowDestructive confirms that the database at a user-supplied
// database.dsn is disposable, letting sqletch reset (drop and
// recreate) its schema. Without it a cold run against a
// user-supplied DSN is refused with SQLETCH204 rather than wiping a
// database a cloned repo pointed sqletch at (H1). A database
// sqletch provisioned itself (empty dsn → a disposable container or
// temp file) is never gated.
AllowDestructive bool
}
RunOptions carries the per-invocation switches that are not sqletch.yaml's business — things a user opts into for one command, which must stay visible on the command line rather than being permanently (and invisibly) disarmed in config.
type WorkspaceCheck ¶
type WorkspaceCheck struct {
Diags map[string][]diagnostics.Diagnostic
Files map[string]*template.QueryFile
Sources map[string][]byte
}
WorkspaceCheck is one consistent snapshot of the workspace's diagnostics, keyed by absolute template path.