sqliteutil

package
v0.9.16 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnExists added in v0.0.406

func ColumnExists(exec Executor, table, column string) (bool, error)

ColumnExists reports whether table contains column.

func IndexExists added in v0.0.406

func IndexExists(exec Executor, index string) (bool, error)

IndexExists reports whether a named index exists.

func ResolveDBPathOverride

func ResolveDBPathOverride(pathOverride string, defaultPath func() (string, error)) (string, error)

ResolveDBPathOverride expands and absolutizes an optional SQLite database path. An empty override delegates to defaultPath; :memory: is returned unchanged.

func SchemaSignature added in v0.0.406

func SchemaSignature(ctx context.Context, db *sql.DB) ([]string, error)

SchemaSignature captures a normalized structural signature for tests and diagnostics. It includes sqlite_master SQL, complete table_info metadata, and foreign-key metadata while excluding SQLite's auto-generated object names. It is intentionally not used by normal migration startup paths.

func TableExists added in v0.0.406

func TableExists(exec Executor, table string) (bool, error)

TableExists reports whether a table or virtual table exists.

func TriggerExists added in v0.0.406

func TriggerExists(exec Executor, trigger string) (bool, error)

TriggerExists reports whether a named trigger exists.

func UserTableCount added in v0.0.406

func UserTableCount(exec Executor) (int, error)

UserTableCount returns the number of non-SQLite-owned tables. It is useful only while classifying an unversioned database on a locked slow path.

func ValidateMigrations added in v0.0.406

func ValidateMigrations(migrations []Migration, firstVersion, targetVersion int, contiguous bool) error

ValidateMigrations validates a migration list. When contiguous is true, the first version must equal firstVersion and every following version must be the next integer. A non-empty list must end at targetVersion.

func WithImmediateMigrationTx

func WithImmediateMigrationTx(ctx context.Context, db *sql.DB, fn func(Executor) error) (err error)

WithImmediateMigrationTx runs fn on a dedicated connection in a SQLite BEGIN IMMEDIATE transaction. SQLite's configured busy_timeout governs lock acquisition; this function does not add an unbounded retry loop.

Cleanup uses a short context independent of ctx, so cancellation cannot skip rollback. If rollback cannot be confirmed, database/sql's Raw hook returns driver.ErrBadConn, which tells the pool to discard rather than reuse the connection.

Types

type Executor

type Executor interface {
	Exec(query string, args ...any) (sql.Result, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
}

Executor is the context-bound query surface exposed to a migration transaction. Implementations must keep every operation on the same SQLite connection.

type Migration added in v0.0.406

type Migration struct {
	Version     int
	Description string
	Up          func(Executor) error
}

Migration is the store-neutral description of one forward schema migration.

Jump to

Keyboard shortcuts

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