Help us shape the future of Go! Take the 2026 Go Developer Survey

driver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package driver abstracts the engine-specific bits of cosql: connection opening, schema introspection, and EXPLAIN prefix. Query/exec themselves go through database/sql directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnInfo

type ColumnInfo struct {
	Name     string
	Type     string
	Nullable bool
	Default  string
}

type Driver

type Driver interface {
	Open() (*sql.DB, error)
	Kind() string // "postgres" or "mysql"
	ListObjects(ctx context.Context, db *sql.DB) ([]SchemaRow, error)
	DescribeTable(ctx context.Context, db *sql.DB, table string) (*TableInfo, error)
	// ExplainSQL wraps a user query into an EXPLAIN that returns rows.
	ExplainSQL(sql string, analyze bool) string
}

Driver is implemented per engine. Callers Open once, pass the *sql.DB to the other methods so connections can be reused.

func For

func For(db config.Database) (Driver, error)

For returns a Driver for the given db config.

type FKInfo

type FKInfo struct {
	Name       string
	Columns    []string
	RefTable   string
	RefColumns []string
}

type IndexInfo

type IndexInfo struct {
	Name    string
	Columns []string
	Unique  bool
	Primary bool
}

type SchemaRow

type SchemaRow struct {
	Schema string
	Name   string
	Kind   string
	Rows   *int64 // approximate, may be nil
}

SchemaRow is one row of `schema` output.

type TableInfo

type TableInfo struct {
	Schema      string
	Name        string
	Columns     []ColumnInfo
	Indexes     []IndexInfo
	ForeignKeys []FKInfo
}

TableInfo is the full description of a single table.

Jump to

Keyboard shortcuts

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