db

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 3 Imported by: 1

Documentation

Overview

Package db object functions that match LXD's object handling patterns.

Package db slice functions that match LXD's slice handling patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareStmts

func PrepareStmts(db *sql.DB, skipErrors bool) error

PrepareStmts prepares all registered statements and stores them in preparedStmts.

func RegisterStmt

func RegisterStmt(sql string) int

RegisterStmt register a SQL statement.

Registered statements will be prepared upfront and re-used, to speed up execution.

Return a unique registration code.

func Scan

func Scan(ctx context.Context, tx *sql.Tx, sql string, rowFunc Dest, inArgs ...any) error

Scan runs a query with inArgs and provides the rowFunc with the scan function for each row. It handles closing the rows and errors from the result set. This implementation matches LXD's Scan function.

func SelectIntegers

func SelectIntegers(ctx context.Context, tx *sql.Tx, query string, args ...any) ([]int, error)

SelectIntegers executes a statement which must yield rows with a single integer column. It returns the list of column values. This implementation matches LXD's SelectIntegers function.

func SelectObjects

func SelectObjects(ctx context.Context, stmt *sql.Stmt, rowFunc Dest, args ...any) error

SelectObjects executes a statement which must yield rows with a specific columns schema. It invokes the given Dest hook for each yielded row. This implementation matches LXD's SelectObjects function.

func SelectStrings

func SelectStrings(ctx context.Context, tx *sql.Tx, query string, args ...any) ([]string, error)

SelectStrings executes a statement which must yield rows with a single string column. It returns the list of column values. This implementation matches LXD's SelectStrings function.

func Stmt

func Stmt(tx *sql.Tx, code int) (*sql.Stmt, error)

Stmt prepares the in-memory prepared statement for the transaction.

func StmtString

func StmtString(code int) (string, error)

StmtString returns the in-memory query string with the given code.

Types

type Dest

type Dest func(scan func(dest ...any) error) error

Dest is a function that is expected to return the objects to pass to the 'dest' argument of sql.Rows.Scan(). It is invoked by SelectObjects once per yielded row, and it will be passed the index of the row being scanned.

type Update

type Update func(ctx context.Context, tx *sql.Tx) error

Update represents a database schema update function. It takes a context and transaction and applies the schema changes.

Jump to

Keyboard shortcuts

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