Documentation ¶
Index ¶
- func Exec[M, A any](conn *sqlite.Conn, query I[M, A]) (_ []*M, err error)
- func FetchMany[M any](conn *sqlite.Conn, query Q[M]) (_ []*M, err error)
- func FetchOne[M any](conn *sqlite.Conn, query Q[M]) (_ *M, err error)
- func ScanAs[T any](stmt *sqlite.Stmt) (*T, error)
- func Tx(conn *sqlite.Conn, fn func(*sqlite.Conn) error) (err error)
- type EmptyResponse
- type I
- type Q
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
Exec executes the given query and returns a slice of zero or more instances of M, if the query return any rows.
func ScanAs ¶
ScanAs scans and return the value T from the given sqlite.Stmt, using reflection for mapping.
func Tx ¶
Tx starts a new transaction and executes the given fn, rolling back if fn returns an error or panics.
This is a utility function for use when directly calling sqlitex.Save would be awkward. Use of this function should be an exception rather than a norm. Use sqlitex.Save directly when possible.
See also: sqlitex.Save
Types ¶
type EmptyResponse ¶
type EmptyResponse struct{}
EmptyResponse is a placeholder type that can be used Q and I to indicate queries that doesn't return any rows.
type I ¶
type I[M, A any] struct { // QueryStr is the sql query used to create a prepared statement QueryStr string // ArgSet is a set of values that are inserted / updated / deleted using // a single prepared statement, i.e. the execution of the query is batched together. ArgSet []A // Bind is used to bind any variables to the given statement Bind func(stmt *sqlite.Stmt, args A) error // Val is used to extract values from the statement and create a new instance of M. // Val can be omitted if QueryStr does not return any rows (eg. INSERT without a RETURNING clause) Val func(stmt *sqlite.Stmt) (*M, error) }
I represents a sqlite write statement, ie. one of INSERT / UPDATE / DELETE.
type Q ¶
type Q[M any] struct { // QueryStr is the sql query used to create a prepared statement QueryStr string // Bind is used to bind any variables to the given statement Bind func(stmt *sqlite.Stmt) error // Val is used to extract values from the statement and create a new instance of M Val func(stmt *sqlite.Stmt) (*M, error) }
Q represents a sqlite query that returns one or more instances of M when executed