Documentation ¶
Index ¶
- Variables
- func All[T any](ctx context.Context, exec Executor, q Query, m scan.Mapper[T], ...) ([]T, error)
- func Allx[T any, Ts ~[]T](ctx context.Context, exec Executor, q Query, m scan.Mapper[T], ...) (Ts, error)
- func Build(q Query) (string, []any, error)
- func BuildN(q Query, start int) (string, []any, error)
- func Cursor[T any](ctx context.Context, exec Executor, q Query, m scan.Mapper[T], ...) (scan.ICursor[T], error)
- func Exec(ctx context.Context, exec Executor, q Query) (int64, error)
- func Express(w io.Writer, d Dialect, start int, e any) ([]any, error)
- func ExpressIf(w io.Writer, d Dialect, start int, e any, cond bool, prefix, suffix string) ([]any, error)
- func ExpressSlice[T any](w io.Writer, d Dialect, start int, expressions []T, prefix, sep, suffix string) ([]any, error)
- func MustBuild(q Query) (string, []any)
- func MustBuildN(q Query, start int) (string, []any)
- func New[T StdInterface](wrapped T) common[T]
- func NewQueryer[T StdQueryer](wrapped T) scan.Queryer
- func One[T any](ctx context.Context, exec Executor, q Query, m scan.Mapper[T], ...) (T, error)
- type BaseQuery
- func (b BaseQuery[E]) Apply(mods ...Mod[E])
- func (q BaseQuery[E]) Build() (string, []any, error)
- func (q BaseQuery[E]) BuildN(start int) (string, []any, error)
- func (b BaseQuery[E]) Clone() BaseQuery[E]
- func (b BaseQuery[E]) GetExtraLoaders() []ExtraLoader
- func (b BaseQuery[E]) GetLoaders() []LoadFunc
- func (b BaseQuery[E]) GetMapperMods() []scan.MapperMod
- func (q BaseQuery[E]) MustBuild() (string, []any)
- func (q BaseQuery[E]) MustBuildN(start int) (string, []any)
- func (b BaseQuery[E]) WriteQuery(w io.Writer, start int) ([]any, error)
- func (b BaseQuery[E]) WriteSQL(w io.Writer, _ Dialect, start int) ([]any, error)
- type Conn
- type DB
- func (d DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
- func (d DB) Close() error
- func (q DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (q DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (q DB) QueryRowContext(ctx context.Context, query string, args ...any) scan.Row
- type Dialect
- type DialectWithNamed
- type ExecOption
- type ExecSettings
- type Executor
- type Expression
- type ExpressionFunc
- type ExtraLoader
- type LoadFunc
- type Loadable
- type MapperModder
- type Mod
- type Query
- type StdInterface
- type StdQueryer
- type Tx
- func (t Tx) Commit() error
- func (q Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (q Tx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (q Tx) QueryRowContext(ctx context.Context, query string, args ...any) scan.Row
- func (t Tx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
var ErrNoNamedArgs = errors.New("Dialect does not support named arguments")
Functions ¶
func Allx ¶
func Allx[T any, Ts ~[]T](ctx context.Context, exec Executor, q Query, m scan.Mapper[T], opts ...ExecOption[T]) (Ts, error)
Allx takes 2 type parameters. The second is a special return type of the returned slice this is especially useful for when the the Query is Loadable and the loader depends on the return value implementing an interface
func Cursor ¶
func Cursor[T any](ctx context.Context, exec Executor, q Query, m scan.Mapper[T], opts ...ExecOption[T]) (scan.ICursor[T], error)
Cursor returns a cursor that works similar to *sql.Rows
func ExpressIf ¶
func ExpressIf(w io.Writer, d Dialect, start int, e any, cond bool, prefix, suffix string) ([]any, error)
ExpressIf expands an express if the condition evaluates to true it can also add a prefix and suffix
func ExpressSlice ¶
func ExpressSlice[T any](w io.Writer, d Dialect, start int, expressions []T, prefix, sep, suffix string) ([]any, error)
ExpressSlice is used to express a slice of expressions along with a prefix and suffix
func MustBuild ¶
MustBuild builds a query and panics on error useful for initializing queries that need to be reused
func New ¶
func New[T StdInterface](wrapped T) common[T]
New wraps an StdInterface to make it comply with Queryer It also includes a number of other methods that are often used with *sql.DB, *sql.Tx and *sql.Conn
func NewQueryer ¶
func NewQueryer[T StdQueryer](wrapped T) scan.Queryer
NewQueryer wraps an StdQueryer and makes it a Queryer
Types ¶
type BaseQuery ¶
type BaseQuery[E Expression] struct { Expression E Dialect Dialect }
BaseQuery wraps common functionality such as cloning, applying new mods and the actual query interface implementation
func (BaseQuery[E]) GetExtraLoaders ¶
func (b BaseQuery[E]) GetExtraLoaders() []ExtraLoader
func (BaseQuery[E]) GetLoaders ¶
func (BaseQuery[E]) GetMapperMods ¶
func (BaseQuery[E]) MustBuild ¶
MustBuild builds the query and panics on error useful for initializing queries that need to be reused
func (BaseQuery[E]) MustBuildN ¶
MustBuildN builds the query and panics on error start numbers the arguments from a different point
func (BaseQuery[E]) WriteQuery ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is similar to *sql.Conn but implements [Queryer]
func NewConn ¶
NewConn wraps an *sql.Conn and returns a type that implements [Queryer] This is useful when an existing *sql.Conn is used in other places in the codebase
func (Conn) ExecContext ¶
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (Conn) PrepareContext ¶
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (Conn) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is similar to *sql.DB but implement [Queryer]
func NewDB ¶
NewDB wraps an *sql.DB and returns a type that implements [Queryer] but still retains the expected methods used by *sql.DB This is useful when an existing *sql.DB is used in other places in the codebase
func OpenDB ¶
OpenDB works just like sql.OpenDB, but converts the returned *sql.DB to DB
func (DB) BeginTx ¶
BeginTx is similar to [sql.DB.BeginTx()], but return a transaction that implements [Queryer]
func (DB) ExecContext ¶
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (DB) PrepareContext ¶
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (DB) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
type DialectWithNamed ¶
type DialectWithNamed interface { Dialect // WriteNamedArg should write an argument placeholder to the writer with the given name WriteNamedArg(w io.Writer, name string) }
Can also write namded args
type ExecOption ¶ added in v0.2.3
type ExecOption[T any] func(*ExecSettings[T])
type ExecSettings ¶ added in v0.2.3
type Executor ¶ added in v0.3.1
type Executor interface { scan.Queryer ExecContext(context.Context, string, ...any) (sql.Result, error) }
func DebugExecutor ¶ added in v0.3.1
type Expression ¶
type ExpressionFunc ¶
type ExtraLoader ¶
type Loadable ¶
type Loadable interface { GetLoaders() []LoadFunc GetExtraLoaders() []ExtraLoader }
type MapperModder ¶
type Query ¶
type Query interface { // It should satisfy the Expression interface so that it can be used // in places such as a sub-select // However, it is allowed for a query to use its own dialect and not // the dialect given to it Expression // start is the index of the args, usually 1. // it is present to allow re-indexing in cases of a subquery // The method returns the value of any args placed WriteQuery(w io.Writer, start int) (args []any, err error) }
type StdInterface ¶
type StdInterface interface { StdQueryer QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
An interface that *sql.DB, *sql.Tx and *sql.Conn satisfy
type StdQueryer ¶
type StdQueryer interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
A Queryer that returns the concrete type *sql.Rows
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is similar to *sql.Tx but implements [Queryer]
func NewTx ¶
NewTx wraps an *sql.Tx and returns a type that implements [Queryer] but still retains the expected methods used by *sql.Tx This is useful when an existing *sql.Tx is used in other places in the codebase
func (Tx) ExecContext ¶
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (Tx) PrepareContext ¶
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (Tx) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
dialect
|
|
gen/drivers
Package drivers talks to various database backends and retrieves table, column, type, and foreign key information
|
Package drivers talks to various database backends and retrieves table, column, type, and foreign key information |
gen/importers
Package importers helps with dynamic imports for templating
|
Package importers helps with dynamic imports for templating |