sqliteutil

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Verdict letting the access go ahead
	AuthOK = sqlite3.SQLITE_OK
	// Verdict failing the statement as not authorized
	AuthDeny = sqlite3.SQLITE_DENY
	// Verdict letting the statement run with that access silently skipped, a column read giving NULL
	AuthIgnore = sqlite3.SQLITE_IGNORE
	// Action of reading a column, arguments table and column; the other action codes are the SQLITE_ constants of modernc.org/sqlite/lib
	ActionRead = sqlite3.SQLITE_READ
	// Action of inserting into a table, first argument the table
	ActionInsert = sqlite3.SQLITE_INSERT
	// Action of updating a column, arguments table and column
	ActionUpdate = sqlite3.SQLITE_UPDATE
	// Action of deleting from a table, first argument the table
	ActionDelete = sqlite3.SQLITE_DELETE
)

Variables

View Source
var ErrClosed = errors.New("sqlite connection is closed")

Error of a driver connection whose database is already closed

View Source
var ErrSameConnection = errors.New("backup source and target are the same connection")

Error of a backup asked to copy a connection onto itself

View Source
var ErrUnsupportedConn = errors.New("connection is not a modernc.org/sqlite connection")

Error of a driver connection that is not a modernc.org/sqlite connection, wrapped with its type

Functions

func Backup

func Backup(src, dst RawConn, pages int, progress func(status, remaining, total int) error, sleep time.Duration) error

Copies the main database of src over the main database of dst with SQLite's online backup: pages per step (every page in one step when not positive), progress called after each step with the step's result code and the pages remaining and in total (its error ends the copy and is returned), sleep paused after a step that found the source busy or locked; a *Error when SQLite fails, also when dst is inside a transaction

func BackupContext

func BackupContext(ctx context.Context, src, dst RawConn, pages int, progress func(status, remaining, total int) error, sleep time.Duration) error

Backup that also stops before a step and during a pause once ctx is done, returning the context's error

func CreateFunction

func CreateFunction(conn RawConn, name string, nArg int, deterministic bool, fn ScalarFunc) error

Registers fn on conn as the SQL function name taking nArg arguments (-1 for any number), replacing one of the same name and count; deterministic lets SQLite treat equal arguments as giving equal results, so the function may serve in indexes and checks; a nil fn removes the function

func InTransaction

func InTransaction(conn RawConn) (bool, error)

Whether a transaction is open on conn

func IsOperational

func IsOperational(code int) bool

Whether a result code, extended or primary, reports an operational failure: one of the database's state or surroundings such as a missing table or column, a lock, a read-only or full disk, an interrupt or a changed schema, not of the statement's values or the caller's use of the API

func SetAuthorizer

func SetAuthorizer(conn RawConn, auth Authorizer) error

Installs auth as the authorizer of conn, consulted for every access of each statement prepared from then on; nil removes it

func SetProgressHandler

func SetProgressHandler(conn RawConn, interrupt func() bool, n int) error

Calls interrupt about every n virtual machine steps of each statement running on conn, the statement failing as interrupted once it answers true; a nil interrupt or an n that is not positive removes the handler

func SetTrace

func SetTrace(conn RawConn, fn func(sql string)) error

Installs fn as the statement trace of conn: it receives each statement as it starts running with its bound parameters written in, statements run from inside another one's step included, and the -- TRIGGER comment SQLite gives for each trigger that fires; nil removes it

func WithHandle

func WithHandle(conn RawConn, fn func(tls *libc.TLS, db uintptr) error) error

Runs fn with the SQLite database handle and libc thread state behind conn while database/sql holds the connection for this call alone

Types

type Authorizer

type Authorizer func(action int, arg1, arg2, database, trigger string) int

Decision on one access SQLite asks about while it prepares a statement: the action code, its two detail arguments (table and column for reads and updates), the database name and the innermost trigger or view, absent arguments empty; it answers AuthOK, AuthDeny or AuthIgnore

type Error

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

Failure SQLite reported on a connection, its extended result code and the database's message; the Code method matches the one modernc.org/sqlite errors have

func (*Error) Code

func (e *Error) Code() int

Extended result code, its low eight bits the primary code such as sqlite3.SQLITE_BUSY

func (*Error) Error

func (e *Error) Error() string

The database's message, as in database is locked

type RawConn

type RawConn interface {
	Raw(func(driverConn any) error) error
}

Connection whose driver connection can be borrowed, as *sql.Conn and the types wrapping one give it

type ScalarFunc

type ScalarFunc func(args []any) (any, error)

Body of a scalar SQL function: it receives the arguments as nil, int64, float64, string or []byte and answers nil, a bool, an integer, a float, a string or a []byte, or an error that becomes the statement's error

Jump to

Keyboard shortcuts

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