Documentation
¶
Index ¶
- Constants
- func NewTracer(fn TraceFn) *tracer
- func SchemaCreate(ctx context.Context, conn Conn, name string) error
- func SchemaDrop(ctx context.Context, conn Conn, name string) error
- func SchemaExists(ctx context.Context, conn Conn, name string) (bool, error)
- type Bind
- func (bind *Bind) Append(key string, value any) bool
- func (bind *Bind) Copy(pairs ...any) *Bind
- func (bind *Bind) Del(key string)
- func (bind *Bind) Exec(ctx context.Context, conn pgx.Tx, query string) error
- func (bind *Bind) Get(key string) any
- func (bind *Bind) Has(key string) bool
- func (bind *Bind) Join(key, sep string) string
- func (bind *Bind) MarshalJSON() ([]byte, error)
- func (bind *Bind) Query(ctx context.Context, conn pgx.Tx, query string) (pgx.Rows, error)
- func (bind *Bind) QueryRow(ctx context.Context, conn pgx.Tx, query string) pgx.Row
- func (bind *Bind) Replace(query string) string
- func (bind *Bind) Set(key string, value any) string
- func (bind *Bind) String() string
- type Conn
- type Err
- type ListReader
- type Listener
- type Notification
- type OffsetLimit
- type Op
- type Opt
- type PoolConn
- type Reader
- type Row
- type Selector
- type TraceFn
- type Writer
Constants ¶
const (
DefaultPort = "5432"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bind ¶
Bind represents a set of variables and arguments to be used in a query. The vars are substituted in the query string itself, while the args are passed as arguments to the query.
func NewBind ¶
Create a new Bind object with the given name/value pairs Returns nil if the number of arguments is not even
func (*Bind) Append ¶
Append a bind var to a list. Returns false if the key is not a list, or the value is not a list.
func (*Bind) Join ¶
Join a bind var with a separator, when it is a []any and return the result as a string. Returns an empty string if the key does not exist.
func (*Bind) MarshalJSON ¶
func (*Bind) Replace ¶
Return a query string with ${subtitution} replaced by the values:
- ${key} => value
- ${'key'} => 'value'
- ${"key"} => "value"
- $1 => $1
- $$ => $$
type Conn ¶
type Conn interface {
// Return a new connection with bound parameters
With(...any) Conn
// Return a connection to a remote database
Remote(database string) Conn
// Perform a transaction within a function
Tx(context.Context, func(Conn) error) error
// Perform a bulk operation within a function (and indicate whether this
// should be in a transaction)
Bulk(context.Context, func(Conn) error) error
// Execute a query
Exec(context.Context, string) error
// Perform an insert
Insert(context.Context, Reader, Writer) error
// Perform an update
Update(context.Context, Reader, Selector, Writer) error
// Perform a delete
Delete(context.Context, Reader, Selector) error
// Perform a get
Get(context.Context, Reader, Selector) error
// Perform a list. If the reader is a ListReader, then the
// count of items is also calculated
List(context.Context, Reader, Selector) error
}
type ListReader ¶
Bind a row to an object, and also count the number of rows
type Listener ¶
type Listener interface {
// Listen to a topic
Listen(context.Context, string) error
// Unlisten from a topic
Unlisten(context.Context, string) error
// Wait for a notification and return it
WaitForNotification(context.Context) (*Notification, error)
// Free resources
Close(context.Context) error
}
Listener is an interface for listening to notifications
type Notification ¶
type OffsetLimit ¶
type OffsetLimit struct {
Offset uint64 `json:"offset,omitempty"`
Limit *uint64 `json:"limit,omitempty"`
}
func (*OffsetLimit) Bind ¶
func (r *OffsetLimit) Bind(bind *Bind, max uint64)
Bind the offset and limit SQL fragment to the bind object
func (*OffsetLimit) Clamp ¶
func (r *OffsetLimit) Clamp(len uint64)
Clamp the limit to the maximum length
type Opt ¶
type Opt func(*opt) error
Opt is a function which applies options for a connection pool
func WithCredentials ¶
Set connection pool username and password. If the database name is not set, then the username will be used as the default database name.
func WithDatabase ¶
Set the database name for the connection. If the user name is not set, then the database name will be used as the user name.
func WithHostPort ¶
Set the hostname and port for the connection. If the port is not set, then the default port 5432 will be used.
func WithSSLMode ¶
Set the postgresql SSL mode. Valid values are "disable", "allow", "prefer", "require", "verify-ca", "verify-full". See https://www.postgresql.org/docs/current/libpq-ssl.html for more information.
type PoolConn ¶
type Selector ¶
type Selector interface {
// Set bind parameters for getting, updating or deleting
Select(*Bind, Op) (string, error)
}
Bind selection parameters for getting, updating or deleting