repl

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
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

func Loop

func Loop(lr LineReader, errOut io.Writer, exec ExecFunc) error

Loop reads statements until EOF (or a quit command) and runs each via exec. Statements are split on `;`. A trailing statement without `;` at EOF is also executed. exec errors are written to errOut and the loop continues.

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

func NewCompleter(schema Schema) *Completer

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

func (c *Completer) Complete(line string, pos int) ([]string, int)

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

type ExecFunc func(sql string) error

ExecFunc runs one complete SQL statement. A returned error is reported but does not stop the loop.

type LineReader

type LineReader interface {
	ReadLine() (string, error)
}

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.

Jump to

Keyboard shortcuts

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