localdb

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package localdb manages the per-request local SQLite database that dfetch loads data sources into and resolves the final query against.

Index

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

func Open(ctx context.Context) (*DB, error)

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

func (db *DB) Attach(ctx context.Context, schema string) error

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

func (db *DB) Close() error

Close releases the pinned connection and the database, then removes the temporary directory holding the on-disk db files.

func (*DB) CreateTable

func (db *DB) CreateTable(ctx context.Context, schema string, ts source.TableSchema) error

CreateTable creates a table matching the schema under the given attached schema name ("" for the default database).

func (*DB) Insert

func (db *DB) Insert(ctx context.Context, schema, table string, cols []string, rows [][]any) error

Insert loads rows into a previously created table in batched multi-row INSERTs. Each row's values must be ordered to match cols.

func (*DB) Query

func (db *DB) Query(ctx context.Context, query string, args ...any) (*Result, error)

Query runs the resolved SQL against the local database and returns the rows, with []byte values normalized to strings. Optional args are bound as query parameters (e.g. sql.Named for :name binds).

type Result

type Result struct {
	Columns []string
	Rows    [][]any
}

Result holds the columns and rows produced by a resolved query.

Jump to

Keyboard shortcuts

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