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

dataset

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package dataset runs a read-only query against a data store and returns its rows. It is the dataset family of requests (see model.Family): a query goes out, rows come back.

A Source runs the queries of one kind of store. Registry maps the driver names a request may use to Sources, so a new store (a CSV file, say) is one more Source and nothing that already works changes. The SQL sources use pure Go drivers only: no cgo, so the lib and the CLI still build everywhere with CGO_ENABLED=0.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is how long a query may take when it sets no timeout.

Variables

View Source
var (
	// ErrUnknownDriver is returned for a driver that is not in the registry.
	ErrUnknownDriver = errors.New("unknown dataset driver")
	// ErrTimeout is returned when the query did not finish in its timeout.
	ErrTimeout = errors.New("the query timed out")
)

The errors a query can end in besides the store's own.

Functions

This section is empty.

Types

type Query

type Query struct {
	Driver    string
	Server    string
	Statement string
	Params    []string
	// Limit is the most rows kept; 0 means model.DefaultDatasetLimit.
	Limit int
	// Root is the directory a relative file path (sqlite) is resolved against.
	Root string
	// Timeout bounds connecting and running together; 0 means DefaultTimeout.
	Timeout time.Duration
}

Query is one query to run. Statement is sent as written; Params are sent apart from it.

type Registry

type Registry map[string]Source

Registry maps a driver name to the Source that runs its queries.

func Default

func Default() Registry

Default is the registry of the built-in stores.

func (Registry) Run

func (r Registry) Run(ctx context.Context, q Query) (Result, error)

Run checks that the statement only reads and runs it on the source of the query's driver.

type Result

type Result struct {
	Columns []string
	Rows    [][]any
	// Truncated is true when the store had more rows than Limit.
	Truncated bool
	Duration  time.Duration
}

Result is what a query returned. Every row has one value per column, in column order; a column that repeats a name gets a numbered suffix (a, a_2) so a row can also be read by name.

type Source

type Source interface {
	Query(ctx context.Context, q Query) (Result, error)
}

Source runs the queries of one kind of store.

Directories

Path Synopsis
Package readonly decides, from the text of a statement alone, whether a query only reads.
Package readonly decides, from the text of a statement alone, whether a query only reads.

Jump to

Keyboard shortcuts

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