Documentation ¶
Index ¶
- Constants
- func DbTxDone[A DbTx](val A)
- func DbTxDoneWith[A DbTx](val A, err error)
- func ScanAny[Src Rows](src Src, out any)
- func ScanNext[Row any, Src ColumnerScanner](src Src) Row
- func ScanVal[Row any, Src Rows](src Src) Row
- func ScanVals[Row any, Src Rows](src Src) (out []Row)
- type Arr
- func (self Arr[A]) Append(buf []byte) []byte
- func (self Arr[A]) AppendInner(buf []byte) []byte
- func (self *Arr[A]) Clear()
- func (self Arr[A]) IsNull() bool
- func (self *Arr[A]) Parse(src string) (err error)
- func (self *Arr[A]) Scan(src any) error
- func (self Arr[A]) String() string
- func (self Arr[A]) Value() (driver.Value, error)
- type ColumnerScanner
- type Db
- type DbConn
- type DbTx
- type DbTxer
- type Rows
Constants ¶
const ErrMultipleRows gg.ErrStr = `expected one row, got multiple`
Returned by `ScanVal` and `ScanAny` when there are too many rows.
Variables ¶
This section is empty.
Functions ¶
func DbTxDone ¶
func DbTxDone[A DbTx](val A)
Must be deferred. Commit if there was no panic, rollback if there was a panic. Usage:
defer DbTxDone(conn)
func DbTxDoneWith ¶ added in v0.0.6
Commit if there was no error, rollback if there was an error. Used internally by `DbTxDone`.
func ScanAny ¶
Decodes `Rows` into the given dynamically typed output. Counterpart to `ScanVals` and `ScanVal` which are statically typed. Output must be a non-nil pointer to one of the following:
- Slice of scalars.
- Slice of structs.
- Single scalar.
- Single struct.
Always closes the rows. If output is not a slice, verifies that there is EXACTLY one row in total, otherwise panics.
func ScanNext ¶ added in v0.0.2
func ScanNext[Row any, Src ColumnerScanner](src Src) Row
Takes `Rows` and decodes the next row into a value of the given type. Output type must be either scalar or struct. Panics on errors. Must be called only after `Rows.Next`.
Types ¶
type Arr ¶
type Arr[A any] []A
Short for "array". A slice type that supports SQL array encoding and decoding, using the `{}` format. Examples:
Arr[int]{10, 20} <-> '{10,20}' Arr[Arr[int]]{{10, 20}, {30, 40}} <-> '{{10,20},{30,40}}'
func ToArr ¶
Shortcut for casting into `Arr`. Workaround for lack of type inference in type literals and casts.
func (Arr[A]) Append ¶
Implement `Appender`, appending the array's SQL encoding to the buffer. If the slice is nil, appends nothing.
func (Arr[A]) AppendInner ¶
Same as `.Append` but without the enclosing `{}`.
type ColumnerScanner ¶
Sub-interface of `Rows` used by `ScanNext`.
type DbConn ¶
type DbConn interface { QueryContext(context.Context, string, ...any) (*sql.Rows, error) ExecContext(context.Context, string, ...any) (sql.Result, error) }
Implemented by stdlib types such as `sql.Conn` and `sql.Tx`.