Documentation
¶
Index ¶
- func BuildInsert(o InsertOpts) (sql string, args []interface{})
- func ExecAll(ctx context.Context, tx pgx.Tx, q ...string) error
- func ExtractException(err error) string
- func InTransaction(ctx context.Context, conn TxStarter, fn func(pgx.Tx) error) (err error)
- func Listen(opts ListenOpts) (err error)
- type InsertOpts
- type ListenOpts
- type TxStarter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildInsert ¶ added in v0.7.0
func BuildInsert(o InsertOpts) (sql string, args []interface{})
Build and cache insert statement for all fields of data. This includes embedded struct fields.
See InsertOpts for further documentation.
func ExtractException ¶ added in v1.1.0
Try to extract an exception message, if err is *pgconn.PgError
func InTransaction ¶
InTransaction runs a function inside a transaction and handles commiting and rollback on error.
Can also be used for nested pseudotransactions via savepoints.
ctx: Context to bind the query to conn: Anything, that can start a new transaction or subtransaction. fn: Function to execute on the transaction.
func Listen ¶
func Listen(opts ListenOpts) (err error)
Listen assigns a function to listen to Postgres notifications on a channel
Types ¶
type InsertOpts ¶ added in v0.7.0
type InsertOpts struct {
// Table to insert into
Table string
// Struct that will have all its public fields written to the database.
//
// Use `db:"name"` to override the default name of a column.
//
// Tags with ",string" after the name will be converted to a string before
// being passed to the driver. This is useful in some cases like encoding to
// Postgres domains. This also works, if the name part of the tag is empty.
// Examples: `db:"name,string"` `db:",string"`
//
// Fields with a `db:"-"` tag will be skipped
//
// First the fields in struct itself are scanned and then the fields in any
// embedded structs using depth first search.
// If duplicate column names (from the struct field name or `db` struct tag)
// exist, the first found value will ber used.
Data interface{}
// Optional prefix to statement
Prefix string
// Optional suffix to statement
Suffix string
}
Options for building insert statement
type ListenOpts ¶
type ListenOpts struct {
// Prevent identical messages from triggering the handler for up to
// DebounceInterval. If 0, all messages trigger the handler.
DebounceInterval time.Duration
// URL to connect to the database on. Required.
ConnectionURL string
// Channel to listen on. Required.
Channel string
// Message handler. Required.
OnMsg func(msg string) error
// Optional error handler
OnError func(err error)
// Optional handler for database connection loss. The connection will be
// automatically reestablished regardless, but this can be used to hook
// extra logic on the library user's side of the application.
OnConnectionLoss func()
// Optional handler for reconnection after database connection loss
OnReconnect func()
// Optional context for cancelling listening
Context context.Context
}
Options for calling Listen()
Click to show internal directories.
Click to hide internal directories.