Documentation
¶
Overview ¶
Package localdb manages the per-request local SQLite database that dfetch loads data sources into and resolves the final query against.
Index ¶
- type DB
- func (db *DB) Attach(ctx context.Context, schema string) error
- func (db *DB) Close() error
- func (db *DB) CreateTable(ctx context.Context, schema string, ts source.TableSchema) error
- func (db *DB) Insert(ctx context.Context, schema, table string, cols []string, rows [][]any) error
- func (db *DB) Query(ctx context.Context, query string, args ...any) (*Result, error)
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a per-request local SQLite database. It is backed by temporary files on disk (under a per-request temp directory) rather than memory, so large result sets spill to disk instead of consuming RAM; the directory is removed on Close.
Every operation runs on a single pinned connection: attached databases are a per-connection property in SQLite, so the schemas attached on one connection are invisible to another. Pinning keeps them all on the same connection.
func Open ¶
Open creates a fresh per-request SQLite database backed by a temporary file on disk and pins a connection to it. The temp file (and any attached-schema files) live under a per-request directory that Close removes.
func (*DB) Attach ¶
Attach attaches a fresh database, backed by a temporary file in the per-request directory, under the given schema name so a schema-qualified table (e.g. github.issues) can be created. It is idempotent; an empty schema (the default "main") is a no-op.
func (*DB) Close ¶
Close releases the pinned connection and the database, then removes the temporary directory holding the on-disk db files.
func (*DB) CreateTable ¶
CreateTable creates a table matching the schema under the given attached schema name ("" for the default database).
func (*DB) Insert ¶
Insert loads rows into a previously created table in batched multi-row INSERTs. Each row's values must be ordered to match cols.