pg_util

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 4 Imported by: 0

README

pg_util

PostgreSQL utilities for Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecAll

func ExecAll(tx *pgx.Tx, q ...string) error

Execute all SQL statement strings and return on first error, if any

func InTransaction

func InTransaction(conn *pgx.ConnPool, fn func(*pgx.Tx) error) (err error)

InTransaction runs a function inside a transaction and handles commiting and rollback on error.

func Listen

func Listen(opts ListenOpts) (err error)

Listen assigns a function to listen to Postgres notifications on a channel

Types

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()

Jump to

Keyboard shortcuts

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