sqlite

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDBLocked = errors.New("SQLite database file is locked by another thread/process, see the logs for " +
	"more information")

ErrDBLocked is returned when attempting to query/execute a query against an SQLite database/transaction which is already locked by another thread/process.

View Source
var ErrQueryReturnedNoRows = errors.New("query returned no rows")

ErrQueryReturnedNoRows is returned when the provided query returned no rows when executed.

Functions

func ExecuteQuery

func ExecuteQuery(db Executable, query Query) (int64, error)

ExecuteQuery executes the provided query against the SQLite database and return the number of rows affected.

func GetPragma

func GetPragma(db Queryable, pragma Pragma, data any) error

GetPragma queries the provided pragma and stores the result in the provided interface; its the job of the caller to ensure the provided type is valid for the value returned by the pragma.

func Open

func Open(path string) (*sql.DB, error)

Open a new SQLite database on disk whilst ensuring that the first time this function is called the SQLite library is initialized by a single thread.

func QueryRow

func QueryRow(db Queryable, query Query, dest ...any) error

QueryRow executes a query that is only expected to return a single row (or where we only care about the first returned row). It's the callers job to ensure the destination types are valid for the expected return value from the query.

func QueryRows

func QueryRows(db Queryable, query Query, callback RowCallback) error

QueryRows execute a query which is expected to return one or more results. The provided callback will be run for each row returned by the query.

func SetPragma

func SetPragma(db Executable, pragma Pragma, value any) error

SetPragma sets the provided pragma to the given value; its the job of the caller to ensure the provided value is of a valid type for the pragma.

Types

type Executable

type Executable interface {
	Exec(query string, args ...any) (sql.Result, error)
}

Executable allows the execute functions defined in this package to work against all the executable types exposed by the 'sql' module for example, '*sql.DB' and '*sql.Tx'.

type Pragma

type Pragma string

Pragma pepresents the string representation of an SQLite PRAGMA which can be used to query the SQLite library for internal (non-table) data.

const (
	// PragmaUserVersion is an integer that is available to applications to use however they want; SQLite makes no use
	// of the user_version itself.
	PragmaUserVersion Pragma = "user_version"

	// PragmaPageSize is size for the database, the value provided to this pragma must be a power of two between 512 and
	// 65536 inclusive.
	PragmaPageSize Pragma = "page_size"

	// PragmaPageCount is the total number of pages in the database file.
	PragmaPageCount Pragma = "page_count"

	// PragmaCacheSize is the suggested maximum number of database disk pages that SQLite will hold in memory at once
	// per open database file.
	PragmaCacheSize Pragma = "cache_size"
)

type Query

type Query struct {
	Query     string
	Arguments []any
}

Query encapsulates a query and its arguments and is used by all the SQLite utility functions in this package.

type Queryable

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

Queryable allows the query functions defined in this package to work against all the queryable types exposed by the 'sql' module for example, '*sql.DB' and '*sql.Tx'.

type RowCallback

type RowCallback func(scan ScanCallback) error

RowCallback is a readability callback which will be run for each row returned by an SQLite query.

type ScanCallback

type ScanCallback func(dest ...any) error

ScanCallback is a readability wrapper around the SQL 'Scan' function.

Jump to

Keyboard shortcuts

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