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 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, conflictColumns ...string) (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 MultiAnd
- type MultiOr
- type QueryEncoder
- func Eq(col string, val any) QueryEncoder
- func Gt(col string, val any) QueryEncoder
- func Gte(col string, val any) QueryEncoder
- func In(col string, val any) QueryEncoder
- func Lt(col string, val any) QueryEncoder
- func Lte(col string, val any) QueryEncoder
- func NotEq(col string, val any) QueryEncoder
- func NotIn(col string, val any) QueryEncoder
- func Order(column string, order ...string) QueryEncoder
- func Raw(s string, args ...any) QueryEncoder
- func Search(col, 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 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) 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) EncodeString ¶
func (t Identifier) EncodeString(b *fast.StringBuffer)
EncodeString implements StringEncoder.
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 string, val any) QueryEncoder
func Gt ¶
func Gt(col string, val any) QueryEncoder
func Gte ¶
func Gte(col string, val any) QueryEncoder
func In ¶
func In(col string, val any) QueryEncoder
func Lt ¶
func Lt(col string, val any) QueryEncoder
func Lte ¶
func Lte(col string, val any) QueryEncoder
func NotEq ¶
func NotEq(col string, val any) QueryEncoder
func NotIn ¶
func NotIn(col string, 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, 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.