Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlite

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sqlite opens the SQLite databases hive and Hive Desktop keep, with the DSN and pool settings every caller must agree on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmbientTx added in v0.63.0

func AmbientTx(ctx context.Context, pool *sql.DB) (*sql.Tx, bool)

AmbientTx returns the transaction that WithinTx opened on pool and attached to ctx, if there is one.

func Open

func Open(ctx context.Context, path string, opts Options) (*sql.DB, error)

Open opens the database at path in WAL mode with foreign keys on, applies the pool settings, and pings it. The caller owns migrations and defaults.

Write transactions begin with BEGIN IMMEDIATE (_txlock=immediate). Several writers, in one process or across the CLI and the desktop, run transactions that read before they write. With the driver default (deferred), two such transactions can both hold a read lock and then both try to upgrade to the write lock. SQLite resolves that deadlock by returning SQLITE_BUSY at once and ignoring busy_timeout, because waiting could never succeed. IMMEDIATE takes the write lock up front, so a second writer waits on busy_timeout instead of failing.

func WithinTx added in v0.63.0

func WithinTx(ctx context.Context, pool *sql.DB, fn func(context.Context, *sql.Tx) error) error

WithinTx runs fn inside a transaction on pool. When ctx already carries one for pool, fn joins it; otherwise WithinTx begins one and hands fn a context that carries it. Only the call that began the transaction commits it or, when fn fails, rolls it back.

Joining is required, not an optimization. Open sets _txlock=immediate, so a nested BEGIN IMMEDIATE waits out busy_timeout for the write lock its own caller holds and then fails with SQLITE_BUSY.

Types

type Options

type Options struct {
	MaxOpenConns int
	MaxIdleConns int
	BusyTimeout  time.Duration
}

Jump to

Keyboard shortcuts

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