Documentation ¶
Overview ¶
Example (EncodeQuery) ¶
buf := fast.NewStringBuffer(256) queryArgs := make([]any, 0, 5) err := encodeQuery(buf, "SELECT * FROM table WHERE foo = %[1]d AND bar != %[1]d AND baz != %d", []any{123, 456}, &queryArgs) if err != nil { panic(err) } fmt.Println(buf.String(), queryArgs)
Output: SELECT * FROM table WHERE foo = $1 AND bar != $2 AND baz != $3 [123 123 456]
Index ¶
- func PrefixSearch(str string) string
- type Alias
- type ChainedIdentifier
- type Cond
- type DB
- func (db *DB) AcquireValues() *Values
- func (db *DB) Close()
- func (db *DB) Delete(ctx context.Context, table Identifier, cond QueryEncoder) (count int64, err error)
- func (db *DB) Exec(ctx context.Context, query string, args ...any) (cmd pgconn.CommandTag, err error)
- func (db *DB) InsertValues(ctx context.Context, table Identifier, vals *Values, options ...InsertOption) (count int64, err error)
- func (db *DB) Query(ctx context.Context, query string, args ...any) (rows pgx.Rows, err error)
- func (db *DB) QueryRow(ctx context.Context, query string, args ...any) (row pgx.Row)
- func (db *DB) ReleaseValues(v *Values)
- func (db *DB) Transaction(ctx context.Context, readOnly ...bool) (tx *Tx, err error)
- func (db *DB) UpdateValues(ctx context.Context, table Identifier, vals *Values, cond QueryEncoder) (count int64, err error)
- type EncodeQuery
- type EncodeString
- type Error
- type Identifier
- type InsertOption
- type MultiAnd
- type MultiOr
- type QueryEncoder
- func Eq(col any, val any) QueryEncoder
- func Gt(col any, val any) QueryEncoder
- func Gte(col any, val any) QueryEncoder
- func In(col any, val any) QueryEncoder
- func Lt(col any, val any) QueryEncoder
- func Lte(col any, val any) QueryEncoder
- func NotEq(col any, val any) QueryEncoder
- func NotIn(col any, val any) QueryEncoder
- func Order(column string, order ...string) QueryEncoder
- func Raw(s string, args ...any) QueryEncoder
- func Search(col any, val string, options ...SearchOptions) QueryEncoder
- type SearchOptions
- type StringEncoder
- type Tx
- type Values
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrefixSearch ¶ added in v0.1.0
Example ¶
fmt.Println(PrefixSearch(" hello world "))
Output: hello:* world:*
Types ¶
type Alias ¶ added in v0.5.0
type Alias [2]StringEncoder
func (Alias) Col ¶ added in v0.5.0
func (t Alias) Col(col string) ChainedIdentifier
func (Alias) EncodeString ¶ added in v0.5.0
func (t Alias) EncodeString(b *fast.StringBuffer)
EncodeString implements StringEncoder.
type ChainedIdentifier ¶ added in v0.4.0
type ChainedIdentifier [2]StringEncoder
func (ChainedIdentifier) Alias ¶ added in v0.5.0
func (t ChainedIdentifier) Alias(col string) Alias
func (ChainedIdentifier) Col ¶ added in v0.4.0
func (t ChainedIdentifier) Col(col string) ChainedIdentifier
func (ChainedIdentifier) EncodeString ¶ added in v0.4.0
func (t ChainedIdentifier) EncodeString(b *fast.StringBuffer)
EncodeString implements StringEncoder.
type Cond ¶
type Cond func(buf *fast.StringBuffer, queryArgs *[]any)
func (Cond) EncodeQuery ¶
func (c Cond) EncodeQuery(buf *fast.StringBuffer, queryArgs *[]any)
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) AcquireValues ¶
func (*DB) Delete ¶
func (db *DB) Delete(ctx context.Context, table Identifier, cond QueryEncoder) (count int64, err error)
func (*DB) Exec ¶
func (db *DB) Exec(ctx context.Context, query string, args ...any) (cmd pgconn.CommandTag, err error)
Execute a query that doesn't return any rows. Arguments are passed in printf syntax.
func (*DB) InsertValues ¶
func (db *DB) InsertValues(ctx context.Context, table Identifier, vals *Values, options ...InsertOption) (count int64, err error)
func (*DB) Query ¶
Query sends a query to the server and returns a Rows to read the results. Only errors encountered sending the query and initializing Rows will be returned. Err() on the returned Rows must be checked after the Rows is closed to determine if the query executed successfully.
The returned Rows must be closed before the connection can be used again. It is safe to attempt to read from the returned Rows even if an error is returned. The error will be the available in rows.Err() after rows are closed. It is allowed to ignore the error returned from Query and handle it in Rows.
It is possible for a call of FieldDescriptions on the returned Rows to return nil even if the Query call did not return an error.
It is possible for a query to return one or more rows before encountering an error. In most cases the rows should be collected before processing rather than processed while receiving each row. This avoids the possibility of the application processing rows from a query that the server rejected. The CollectRows function is useful here.
func (*DB) QueryRow ¶
QueryRow is a convenience wrapper over Query. Any error that occurs while querying is deferred until calling Scan on the returned Row. That Row will error with ErrNoRows if no rows are returned.
func (*DB) ReleaseValues ¶
func (*DB) Transaction ¶
func (*DB) UpdateValues ¶
func (db *DB) UpdateValues(ctx context.Context, table Identifier, vals *Values, cond QueryEncoder) (count int64, err error)
type EncodeQuery ¶ added in v0.2.0
type EncodeQuery func(buf *fast.StringBuffer, queryArgs *[]any)
func Multiple ¶ added in v0.2.0
func Multiple(enc ...QueryEncoder) EncodeQuery
func (EncodeQuery) EncodeQuery ¶ added in v0.2.0
func (fn EncodeQuery) EncodeQuery(buf *fast.StringBuffer, queryArgs *[]any)
type EncodeString ¶ added in v0.2.0
type EncodeString func(buf *fast.StringBuffer)
func (EncodeString) EncodeString ¶ added in v0.2.0
func (fn EncodeString) EncodeString(buf *fast.StringBuffer)
type Identifier ¶
type Identifier string
func (Identifier) Alias ¶ added in v0.5.0
func (t Identifier) Alias(col string) Alias
func (Identifier) Col ¶ added in v0.4.0
func (t Identifier) Col(col string) ChainedIdentifier
func (Identifier) EncodeString ¶
func (t Identifier) EncodeString(b *fast.StringBuffer)
EncodeString implements StringEncoder.
type InsertOption ¶ added in v0.6.0
type InsertOption func(vals *Values) EncodeQuery
func Upsert ¶ added in v0.6.0
func Upsert(numConflictingColumns int, ignoreColumns ...string) InsertOption
type MultiAnd ¶
type MultiAnd interface { QueryEncoder And(QueryEncoder) MultiAnd }
func And ¶
func And(ops ...QueryEncoder) MultiAnd
type MultiOr ¶
type MultiOr interface { QueryEncoder Or(QueryEncoder) MultiOr }
func Or ¶
func Or(ops ...QueryEncoder) MultiOr
type QueryEncoder ¶
type QueryEncoder interface {
EncodeQuery(buf *fast.StringBuffer, queryArgs *[]any)
}
func Eq ¶
func Eq(col any, val any) QueryEncoder
func Gt ¶
func Gt(col any, val any) QueryEncoder
func Gte ¶
func Gte(col any, val any) QueryEncoder
func In ¶
func In(col any, val any) QueryEncoder
func Lt ¶
func Lt(col any, val any) QueryEncoder
func Lte ¶
func Lte(col any, val any) QueryEncoder
func NotEq ¶
func NotEq(col any, val any) QueryEncoder
func NotIn ¶
func NotIn(col any, val any) QueryEncoder
func Order ¶ added in v0.2.0
func Order(column string, order ...string) QueryEncoder
func Raw ¶
func Raw(s string, args ...any) QueryEncoder
func Search ¶ added in v0.1.0
func Search(col any, val string, options ...SearchOptions) QueryEncoder
type SearchOptions ¶ added in v0.1.0
type StringEncoder ¶ added in v0.2.0
type StringEncoder = fast.StringEncoder
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
type Values ¶
type Values struct {
// contains filtered or unexported fields
}
func (*Values) EncodeQuery ¶ added in v0.2.0
func (r *Values) EncodeQuery(buf *fast.StringBuffer, queryArgs *[]any)
EncodeQuery implements QueryEncoder.
Source Files ¶
- alias.go
- cond.go
- cond_compare.go
- cond_multi.go
- cond_search.go
- conn_memory.go
- db.go
- delete.go
- error.go
- identifier.go
- identifier_chain.go
- insert_values.go
- order_by.go
- query.go
- query_encoder.go
- query_encoder_multiple.go
- raw.go
- rows.go
- string_encoder.go
- transaction.go
- update_values.go
- utils.go
- values.go