Documentation ¶
Index ¶
- Variables
- func ExecuteQuery(db Executable, query Query) (int64, error)
- func GetPragma(db Queryable, pragma Pragma, data any) error
- func Open(path string) (*sql.DB, error)
- func QueryRow(db Queryable, query Query, dest ...any) error
- func QueryRows(db Queryable, query Query, callback RowCallback) error
- func SetPragma(db Executable, pragma Pragma, value any) error
- type Executable
- type Pragma
- type Query
- type Queryable
- type RowCallback
- type ScanCallback
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
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 ¶
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.
Types ¶
type Executable ¶
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 ¶
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 ¶
ScanCallback is a readability wrapper around the SQL 'Scan' function.