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

sql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package sql is the database adapter for SQL servers: one implementation, a dialect per driver (postgres, mssql, mysql) for listing, creating and dropping databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(env core.Env, c *spec.Component) (any, error)

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func (*DB) Actions

func (d *DB) Actions() []core.Action

func (*DB) Activity

func (d *DB) Activity(ctx context.Context) (core.Activity, error)

func (*DB) Browse

func (d *DB) Browse(ctx context.Context, path []string) (core.Table, bool, error)

Browse walks the server: databases, then a database's object kinds, then the objects, then one object's first rows (tables, views) or definition (procedures, functions).

func (*DB) Close

func (d *DB) Close() error

func (*DB) CreateDatabase

func (d *DB) CreateDatabase(ctx context.Context, name string) error

func (*DB) Databases

func (d *DB) Databases(ctx context.Context) ([]string, error)

func (*DB) Delete

func (d *DB) Delete(ctx context.Context, path []string, t core.Table, rows []int) error

func (*DB) DropDatabase

func (d *DB) DropDatabase(ctx context.Context, name string) error

func (*DB) Exec

func (d *DB) Exec(ctx context.Context, db, q string) (int64, error)

func (*DB) Fresh

func (d *DB) Fresh(ctx context.Context) (bool, error)

Fresh is whether the database has no tables of its own yet (or does not exist), waiting up to 30s for a server that is still starting.

func (*DB) Host

func (d *DB) Host() string

Host is the rig service the database runs in: the one svc:// in addr names.

func (*DB) Ping

func (d *DB) Ping(ctx context.Context) error

func (*DB) Query

func (d *DB) Query(ctx context.Context, db, q string) (core.Table, error)

func (*DB) QueryAt

func (d *DB) QueryAt(ctx context.Context, path []string, q string) (core.Table, error)

QueryAt runs q in the database the path starts at.

func (*DB) QueryLanguage

func (d *DB) QueryLanguage() string

func (*DB) Restore

func (d *DB) Restore(ctx context.Context, file string, log io.Writer) error

Restore replaces the database's contents with file's.

func (*DB) RunQuery

func (d *DB) RunQuery(ctx context.Context, q string) (core.Table, error)

RunQuery runs q on the default database; "@name <sql>" picks another.

func (*DB) Seed

func (d *DB) Seed(ctx context.Context, out io.Writer) error

Seed runs the configured seed steps in order.

func (*DB) Set

func (d *DB) Set(ctx context.Context, path []string, t core.Table, row, col int, value string) error

Set writes value into one cell; the text NULL stores NULL.

func (*DB) Snapshot

func (d *DB) Snapshot(ctx context.Context, file string, log io.Writer) error

Snapshot dumps the database into file: pg_dump or mysqldump on this machine, or inside the database's container when this machine has none (or a different version); SQL Server backs up to its own disk and the file is copied out of its container.

func (*DB) SuggestQuery

func (d *DB) SuggestQuery(ctx context.Context, path []string) string

SuggestQuery reads a table or view's first rows, and calls a procedure or function with each parameter as NULL /* its type */ to fill in; elsewhere it leaves a SELECT to finish.

func (*DB) SuggestRowQuery

func (d *DB) SuggestRowQuery(ctx context.Context, path []string, t core.Table, row int) string

SuggestRowQuery reads the row back by its primary key, or by its first column when it has none.

type Options

type Options struct {
	Driver   string            `yaml:"driver"`
	Addr     string            `yaml:"addr"`
	User     string            `yaml:"user"`
	Password string            `yaml:"password"`
	Database string            `yaml:"database"`
	Params   map[string]string `yaml:"params"`
	// Seed fills the database: rig data seed, and rig up when it starts the database empty.
	Seed  []Seed `yaml:"seed"`
	Seeds []Seed `yaml:"seeds"` // the old name of seed
	// Clear holds the statements `clear` runs to empty the run's data without recreating the database.
	Clear []string `yaml:"clear"`
}

type Seed

type Seed struct {
	File    string `yaml:"file"`
	Command string `yaml:"command"`
	DB      string `yaml:"db"`
}

Seed is one step of filling a database: a SQL file run on it, or a shell command run from the project directory with RIG_DB_ADDR (host:port, reachable from here) and RIG_DB_NAME set.

Jump to

Keyboard shortcuts

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