Documentation
¶
Overview ¶
Package sqlitexx provides another set of extensions for the sqlitex package.
Index ¶
- Variables
- type Pool
- type PoolOptions
- type Query
- func (q *Query) BindBytes(name string, value []byte) *Query
- func (q *Query) BindInt(name string, value int) *Query
- func (q *Query) BindInt64(name string, value int64) *Query
- func (q *Query) BindString(name, value string) *Query
- func (q *Query) BindStringIfSet(name, value string) *Query
- func (q *Query) BindUint64(name string, value uint64) *Query
- func (q *Query) Exec() (err error)
- func (q *Query) QueryAll(resultFn ResultFunc) (err error)
- func (q *Query) QueryIter() iter.Seq2[*sqlite.Stmt, error]
- func (q *Query) QueryRow(resultFn ResultFunc) (err error)
- type ResultFunc
Constants ¶
This section is empty.
Variables ¶
var ErrNoRows = errors.New("sqlitexx: no rows in result set")
ErrNoRows is returned when a query returns no rows.
Functions ¶
This section is empty.
Types ¶
type Pool ¶ added in v0.4.0
type Pool struct {
// contains filtered or unexported fields
}
Pool is a dynamically-sized pool of SQLite connections.
Connections are created on demand up to HighWatermark. Up to LowWatermark idle connections are retained; any extras are closed when returned. It is safe for concurrent use by multiple goroutines.
func NewPool ¶ added in v0.4.0
func NewPool(uri string, opts PoolOptions) (*Pool, error)
NewPool opens a dynamically-sized pool of SQLite connections.
func (*Pool) Close ¶ added in v0.4.0
Close interrupts and closes all connections, waiting for in-use connections to be returned via Pool.Put.
func (*Pool) Put ¶ added in v0.4.0
Put returns a connection to the pool.
Put panics if conn was not obtained from this pool. Put(nil) is a no-op.
If the number of idle connections is below LowWatermark, the connection is cached; otherwise it is closed immediately.
func (*Pool) Take ¶ added in v0.4.0
Take returns an SQLite connection from the Pool.
If no connection is available and the high watermark has been reached, Take blocks until a connection is returned, the context is canceled, or the pool is closed. The context also controls the connection's interrupt lifetime via sqlite.Conn.SetInterrupt.
All non-nil connections returned by Take must be returned via Pool.Put.
type PoolOptions ¶ added in v0.4.0
type PoolOptions struct {
// Flags is interpreted the same way as the argument to [sqlite.Open].
// A Flags value of 0 defaults to:
//
// - SQLITE_OPEN_READWRITE
// - SQLITE_OPEN_CREATE
// - SQLITE_OPEN_WAL
// - SQLITE_OPEN_URI
Flags sqlite.OpenFlags
// LowWatermark is the minimum number of idle connections kept in the pool.
// When a connection is returned and the idle count is below this threshold,
// the connection is cached; otherwise it is closed.
//
// Default is 2.
LowWatermark int
// HighWatermark is the maximum total number of connections (idle + in-use).
// Take will block until a connection becomes available if this limit is reached.
//
// Default is 10. Must be >= LowWatermark.
HighWatermark int
}
PoolOptions configures NewPool.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents a prepared SQL query.
func NewQuery ¶
NewQuery creates a query that can be executed.
NewQuery supports only named parameters. The query should be executed to free up prepared resources.
func (*Query) BindString ¶
BindString binds a string parameter.
func (*Query) BindStringIfSet ¶
BindStringIfSet binds a string parameter if the value is not empty.
func (*Query) BindUint64 ¶
BindUint64 binds a uint64 parameter.
func (*Query) QueryAll ¶
func (q *Query) QueryAll(resultFn ResultFunc) (err error)
QueryAll executes the query and processes all returned rows.
func (*Query) QueryIter ¶
QueryIter returns an iterator for the query results.
The statement is reset when the iteration completes or breaks early.
func (*Query) QueryRow ¶
func (q *Query) QueryRow(resultFn ResultFunc) (err error)
QueryRow executes the query and asserts a single row.
If no rows are returned, ErrNoRows is returned.
type ResultFunc ¶
ResultFunc is a function that processes a row from a query result.