gsql

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 NextVal

func NextVal[Val any, Src ColumnerScanner](src Src) Val

func RowsCols

func RowsCols[A Columner](val A) []string

func RowsDone

func RowsDone[A io.Closer](val A)

func RowsErr

func RowsErr[A Errer](val A) error

func RowsOk

func RowsOk[A Errer](val A)

func RowsScan

func RowsScan[A Scanner](src A, buf []any)

func ScanAny

func ScanAny[Src Rows](src Src, out any)

func ScanVal

func ScanVal[Val any, Src Rows](src Src) Val

func ScanVals

func ScanVals[Val any, Src Rows](src Src) (out []Val)

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 ArrOf

func ArrOf[A any](val ...A) Arr[A]

Shortcut for creating `Arr` from the arguments.

func ToArr

func ToArr[A any](val []A) Arr[A]

Shortcut for casting into `Arr`. Workaround for lack of type inference in type literals and casts.

func (Arr[A]) Append

func (self Arr[A]) Append(buf []byte) []byte

Implement `Appender`, appending the array's SQL encoding to the buffer. If the slice is nil, appends nothing.

func (Arr[A]) AppendInner

func (self Arr[A]) AppendInner(buf []byte) []byte

Same as `.Append` but without the enclosing `{}`.

func (*Arr[A]) Clear

func (self *Arr[A]) Clear()

Truncates the length, keeping the capacity.

func (Arr[A]) Get

func (self Arr[A]) Get() any

Implement `Getter` for compatibility with 3rd party libraries such as `pgx`. If the slice is nil, returns nil. Otherwise returns the SQL-encoded string representation.

func (Arr[A]) IsNull

func (self Arr[A]) IsNull() bool

Implement `Nullable`. True if the slice is nil.

func (*Arr[A]) Parse

func (self *Arr[A]) Parse(src string) (err error)

Decodes from an SQL array literal string. Supports nested arrays.

func (*Arr[A]) Scan

func (self *Arr[A]) Scan(src any) error

Implement `sql.Scanner`.

func (Arr[A]) String

func (self Arr[A]) String() string

Implement `fmt.Stringer`. Returns an SQL encoding of the array.

func (Arr[A]) Value

func (self Arr[A]) Value() (driver.Value, error)

Implement `driver.Valuer`.

type Columner

type Columner interface{ Columns() ([]string, error) }

type ColumnerScanner

type ColumnerScanner interface {
	Columner
	Scanner
}

type Db

type Db interface {
	DbConn
	DbTxer
}

Implemented by stdlib types such as `sql.DB`.

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`.

type DbTx

type DbTx interface {
	DbConn
	Commit() error
	Rollback() error
}

Implemented by stdlib types such as `sql.Tx`.

type DbTxer

type DbTxer interface {
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
}

Implemented by stdlib types such as `sql.DB`.

type Errer

type Errer interface{ Err() error }

type Nexter

type Nexter interface{ Next() bool }

type Rows

type Rows interface {
	io.Closer
	Errer
	Nexter
	ColumnerScanner
}

Interface of `sql.Rows`. Used by various scanning tools.

type Scanner

type Scanner interface{ Scan(...any) error }

Jump to

Keyboard shortcuts

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