driver

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: 3 Imported by: 0

Documentation

Overview

Package driver defines the database driver abstraction for s9l.

All database-specific behavior lives behind these interfaces; the core (cli/repl/render/history) depends only on them. Adding a new database means adding one driver package that implements Driver and registers itself via Register — without touching the core. This is the extensibility hinge described in docs/PLAN.md, so change it deliberately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns the sorted list of registered driver names.

func Register

func Register(d Driver)

Register makes a driver available by its Name. It is intended to be called from driver package init functions. It panics on a nil driver or duplicate name, both of which are programmer errors detectable at startup.

Types

type Conn

type Conn interface {
	// Query runs a statement that returns rows; rows are streamed.
	Query(ctx context.Context, query string, args ...any) (Rows, error)
	// Exec runs a statement that does not return rows.
	Exec(ctx context.Context, query string, args ...any) (Result, error)
	// Close releases the connection.
	Close() error
}

Conn is a live database connection.

func Open

func Open(ctx context.Context, name, dsn string) (Conn, error)

Open looks up the named driver and opens a connection with the given DSN. Connection failures are wrapped with the driver name for context.

type Driver

type Driver interface {
	// Name is the unique identifier of the driver, e.g. "sqlite", "postgres".
	//
	// It doubles as the DSN scheme: callers select a driver by this name (see
	// Open/Get). An earlier design split this into Name() and Scheme(), but a
	// single value keeps registration and selection unambiguous and avoids a
	// second source of truth; we merge them deliberately.
	Name() string
	// Open establishes a connection using a driver-specific DSN.
	Open(ctx context.Context, dsn string) (Conn, error)
}

Driver opens connections to a specific database system.

func Get

func Get(name string) (Driver, error)

Get returns the driver registered under name.

type Metadata

type Metadata interface {
	// Databases lists databases/schemas (\l).
	Databases(ctx context.Context) (Rows, error)
	// Tables lists tables in the current database (\dt).
	Tables(ctx context.Context) (Rows, error)
	// Columns describes the columns of a table (\d <table>).
	Columns(ctx context.Context, table string) (Rows, error)
}

Metadata is an optional capability a Conn may also implement to introspect the schema, backing the \l, \dt and \d meta-commands. Each result is a normal streaming Rows so it renders through the same path as a query. Drivers that don't implement it simply don't support those commands. The dialect-specific SQL lives in each driver, keeping these differences out of the core.

type Result

type Result interface {
	// RowsAffected returns the number of rows affected by the statement.
	RowsAffected() (int64, error)
}

Result reports the outcome of an Exec.

type Rows

type Rows interface {
	// Columns returns the column names of the result set.
	Columns() []string
	// Next advances to the next row, returning false at end-of-rows or on
	// error (check Err afterwards).
	Next() bool
	// Values returns the current row's column values. A SQL NULL is
	// represented as a nil any.
	Values() ([]any, error)
	// Err returns the first non-EOF error encountered during iteration.
	Err() error
	// Close releases resources held by the cursor.
	Close() error
}

Rows is a forward-only, streaming cursor. Callers must Close it.

Directories

Path Synopsis
Package clickhouse implements the s9l driver for ClickHouse using the pure-Go ClickHouse/clickhouse-go/v2 adapter (database/sql, no CGO).
Package clickhouse implements the s9l driver for ClickHouse using the pure-Go ClickHouse/clickhouse-go/v2 adapter (database/sql, no CGO).
Package drivertest provides a conformance suite that every driver.Driver implementation must pass.
Package drivertest provides a conformance suite that every driver.Driver implementation must pass.
Package mysql implements the s9l driver for MySQL using the pure-Go go-sql-driver/mysql adapter (database/sql, no CGO).
Package mysql implements the s9l driver for MySQL using the pure-Go go-sql-driver/mysql adapter (database/sql, no CGO).
Package postgres implements the s9l driver for PostgreSQL using the pure-Go jackc/pgx stdlib adapter (database/sql, no CGO).
Package postgres implements the s9l driver for PostgreSQL using the pure-Go jackc/pgx stdlib adapter (database/sql, no CGO).
Package sqlite implements the s9l driver for SQLite using the pure-Go modernc.org/sqlite driver (CGO-free), keeping cross-compilation and single-binary distribution intact.
Package sqlite implements the s9l driver for SQLite using the pure-Go modernc.org/sqlite driver (CGO-free), keeping cross-compilation and single-binary distribution intact.
Package sqlserver implements the s9l driver for Microsoft SQL Server using the pure-Go microsoft/go-mssqldb adapter (database/sql, no CGO).
Package sqlserver implements the s9l driver for Microsoft SQL Server using the pure-Go microsoft/go-mssqldb adapter (database/sql, no CGO).

Jump to

Keyboard shortcuts

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