pg_util

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 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 *sql.Tx, q ...string) error

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

func InTransaction

func InTransaction(db *sql.DB, fn func(*sql.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 on to the database. Required.
	ConnectionURL string

	// Channel to listen on. Required.
	Channel string

	// Message handler. Required.
	OnMsg func(msg string) error

	// Optional connection loss handler
	OnConnectionLoss func() error

	// Optional error handler
	OnError func(err error)

	// Optional channel for cancelling listening
	Canceller <-chan struct{}
}

Options for calling Listen()

Jump to

Keyboard shortcuts

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