db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package db implements the database runner: it runs a SQL statement from a `query:` step through a named db runner and captures the result — rows (for a SELECT) as a JSON array, or the affected-row count (for INSERT/UPDATE/DDL) — as a runner.Result (ADR-0026). It is the atago counterpart to runn's DB runner. Only pure-Go drivers are linked in (no cgo): SQLite via modernc.org/sqlite, PostgreSQL via lib/pq, MySQL via go-sql-driver/mysql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateDriver

func ValidateDriver(driver string) error

ValidateDriver reports whether an explicitly declared runner.driver is one of the supported names/aliases. It is meant for the loader, which wants to reject a bad driver before execution begins; an empty driver is always valid because it is inferred from the dsn at resolution time.

Types

type Config

type Config struct {
	// Driver is a database/sql driver name: sqlite, postgres, or mysql.
	Driver string
	// DataSource is the driver-specific DSN (path for sqlite, URL/native for the
	// servers).
	DataSource string
	// Timeout bounds a single query; zero means no timeout.
	Timeout time.Duration
}

Config is the resolved configuration for a db runner.

func Resolve

func Resolve(driver, dsn string) (Config, error)

Resolve derives a Config from a runner's optional driver and its dsn. When driver is empty it is inferred from the dsn scheme (sqlite:, postgres://, mysql://); a native DSN with no recognizable scheme requires an explicit driver.

type Runner

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

Runner holds an open database/sql pool for one db runner.

func Open

func Open(cfg Config) (*Runner, error)

Open opens (lazily — database/sql does not connect until first use) a pool for the configuration.

func (*Runner) Close

func (r *Runner) Close() error

Close releases the pool.

func (*Runner) Query

func (r *Runner) Query(ctx context.Context, query string) (*runner.Result, error)

Query runs one SQL statement. A row-returning statement (SELECT, WITH, …) has its rows captured as a JSON array; any other statement is executed and its affected-row count recorded.

Jump to

Keyboard shortcuts

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