pg

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrefixSearch added in v0.1.0

func PrefixSearch(str string) string
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 NewDB

func NewDB(db *pgxpool.Pool) *DB

func (*DB) AcquireValues

func (db *DB) AcquireValues() *Values

func (*DB) Close added in v0.0.2

func (db *DB) Close()

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) (pgconn.CommandTag, error)

Exec executes sql. sql can be either a prepared statement name or an SQL string. arguments should be referenced positionally from the sql string as $1, $2, etc.

func (*DB) InsertValues

func (db *DB) InsertValues(ctx context.Context, table Identifier, vals *Values, conflictColumns ...string) (count int64, err error)

func (*DB) Query

func (db *DB) Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)

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

func (db *DB) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

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 *DB) ReleaseValues(v *Values)

func (*DB) Transaction

func (db *DB) Transaction(ctx context.Context, readOnly ...bool) (tx *Tx, err error)

func (*DB) UpdateValues

func (db *DB) UpdateValues(ctx context.Context, table Identifier, vals *Values, cond QueryEncoder) (count int64, err error)

type Error

type Error struct {
	// contains filtered or unexported fields
}

func (Error) Args

func (err Error) Args() []any

func (Error) Error

func (err Error) Error() string

func (Error) Query

func (err Error) Query() string

func (Error) String

func (err Error) String() string

type Identifier

type Identifier string

func (Identifier) EncodeString

func (t Identifier) EncodeString(b *fast.StringBuffer)

EncodeString implements fast.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 Raw

func Raw(s string, args ...any) QueryEncoder
func Search(col, val string, options ...SearchOptions) QueryEncoder

type SearchOptions added in v0.1.0

type SearchOptions struct {
	Dictionary   string
	Preprocessor func(string) string
}

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

func (*Tx) Commit

func (tx *Tx) Commit(ctx ...context.Context) (err error)

func (*Tx) Deadline

func (tx *Tx) Deadline() (deadline time.Time, ok bool)

Deadline implements context.Context.

func (*Tx) Done

func (tx *Tx) Done() <-chan struct{}

Done implements context.Context.

func (*Tx) Err

func (tx *Tx) Err() error

Err implements context.Context.

func (*Tx) Rollback

func (tx *Tx) Rollback(ctx ...context.Context) (err error)

func (*Tx) Value

func (tx *Tx) Value(key any) any

Value implements context.Context.

type Values

type Values struct {
	// contains filtered or unexported fields
}

func (*Values) Empty

func (r *Values) Empty() bool

func (*Values) Len

func (r *Values) Len() int

func (*Values) Value

func (r *Values) Value(column string, value any) *Values

Jump to

Keyboard shortcuts

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