Documentation
¶
Overview ¶
Package repl provides the interactive read-eval-print loop: it reads lines from a LineReader, splits them into `;`-terminated statements, and dispatches each to an exec callback. The core loop is terminal-independent so it can be unit-tested with a slice-backed reader; the cmd layer wires a readline-backed reader for real terminals. See docs/TASKS.md C3.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInterrupt = errors.New("repl: interrupted")
ErrInterrupt signals that the current input line was interrupted (Ctrl-C). The loop discards the pending buffer and continues.
Functions ¶
Types ¶
type Completer ¶ added in v0.5.0
type Completer struct {
// contains filtered or unexported fields
}
Completer offers word completions for the REPL: backslash meta-commands, SQL keywords, table names, and column names (including qualified table.column and columns of tables referenced in the current line). It is terminal-independent so it can be unit-tested; cmd wires it to readline's AutoCompleter.
func NewCompleter ¶ added in v0.5.0
NewCompleter returns a Completer backed by schema (which may be nil, in which case only keywords and meta-commands are offered).
func (*Completer) Complete ¶ added in v0.5.0
Complete returns the candidate completions (as the suffix to append after the already-typed prefix) for the word ending at pos in line, together with the rune length of that prefix. The contract matches readline.AutoCompleter.Do: the prefix length is used only for display alignment.
type ExecFunc ¶
ExecFunc runs one complete SQL statement. A returned error is reported but does not stop the loop.
type LineReader ¶
LineReader yields input lines. ReadLine returns io.EOF at end of input and ErrInterrupt when the user interrupts the current line.
type Schema ¶ added in v0.5.0
type Schema interface {
// Tables returns the table names in the current database.
Tables() []string
// Columns returns the column names of the given table.
Columns(table string) []string
}
Schema supplies names for SQL completion. Implementations are expected to cache results (metadata lookups are relatively expensive); all methods must be safe to call repeatedly and may return nil when unavailable.
func NewSchemaCache ¶ added in v0.13.0
func NewSchemaCache(ctx context.Context, conn driver.Conn, store *schemacache.Store, connID string) Schema
NewSchemaCache returns a Schema for conn, or nil if conn lacks the Metadata capability (completion then falls back to keywords only). store and connID may be zero to disable persistence.