database

package
v0.0.0-...-0eb8f9d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec[M, A any](conn *sqlite.Conn, query I[M, A]) (_ []*M, err error)

Exec executes the given query and returns a slice of zero or more instances of M, if the query return any rows.

func FetchMany

func FetchMany[M any](conn *sqlite.Conn, query Q[M]) (_ []*M, err error)

FetchMany runs the given query and returns a slice of zero or more instances of M

func FetchOne

func FetchOne[M any](conn *sqlite.Conn, query Q[M]) (_ *M, err error)

FetchOne runs the given query and returns either nil or a single instance of M

func ScanAs

func ScanAs[T any](stmt *sqlite.Stmt) (*T, error)

ScanAs scans and return the value T from the given sqlite.Stmt, using reflection for mapping.

func Tx

func Tx(conn *sqlite.Conn, fn func(*sqlite.Conn) error) (err error)

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

Directories

Path Synopsis
Package schema provides the sqlite schema migrations and utility functions to apply those.
Package schema provides the sqlite schema migrations and utility functions to apply those.

Jump to

Keyboard shortcuts

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