sqlutil

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuoteID

func QuoteID(parts ...string) string

func Rollback added in v0.31.0

func Rollback(ctx context.Context, errMsg string, tx *sql.Tx)

Rollback will roll back the transaction, logging any potential errors other than ErrTxDone and ErrConnDone, which are expected.

Primarily, it's intended to be used with defer as an alternative to calling defer tx.Rollback() which ignores ALL errors.

func RollbackContext added in v0.31.0

func RollbackContext(ctx context.Context, errMsg string, tx Tx)

RollbackContext provides the same functionality as Rollback, but for a pgx.Tx.

func SplitQuery added in v0.32.0

func SplitQuery(query string) []string

SplitQuery will split a SQL query into individual queries.

It will split on semicolons, but will ignore semicolons inside of $$ blocks.

Types

type BoolArray

type BoolArray []bool

func (*BoolArray) Scan

func (s *BoolArray) Scan(src interface{}) error

func (BoolArray) Value

func (s BoolArray) Value() (driver.Value, error)

type Error

type Error struct {
	Code           string
	Message        string
	Detail         string
	Hint           string
	TableName      string
	ConstraintName string
	Where          string
	ColumnName     string
	Position       int
	// contains filtered or unexported fields
}

Error represents a driver-agnostic SQL error.

func MapError

func MapError(err error) *Error

MapError will return a Error from the given err object or nil otherwise.

func (Error) Error

func (e Error) Error() string

type IntArray

type IntArray []int

func (*IntArray) Scan

func (a *IntArray) Scan(src interface{}) error

func (IntArray) Value

func (a IntArray) Value() (driver.Value, error)

type Listener

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

Listener will listen for NOTIFY commands on a set of channels.

func NewListener

func NewListener(ctx context.Context, logger *log.Logger, db *sql.DB, channels ...string) (*Listener, error)

NewListener will create and initialize a Listener which will automatically reconnect and listen to the provided channels.

func (*Listener) Close

func (l *Listener) Close() error

Close performs a shutdown with a background context.

func (*Listener) Errors

func (l *Listener) Errors() <-chan error

Errors will return a channel that will be fed errors from this listener.

func (*Listener) Notifications

func (l *Listener) Notifications() <-chan *pgconn.Notification

Notifications returns the notification channel for this listener. Nil values will not be returned until the listener is closed.

func (*Listener) Shutdown added in v0.25.0

func (l *Listener) Shutdown(context.Context) error

Shutdown will shut down the listener and returns after all connections have been completed. It is not necessary to call Stop() before Close().

func (*Listener) Start

func (l *Listener) Start()

Start will enable reconnections and messages.

func (*Listener) Stop

func (l *Listener) Stop()

Stop will end all current connections and stop reconnecting.

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not null
}

func (*NullTime) Scan

func (n *NullTime) Scan(src interface{}) error

func (NullTime) Value

func (n NullTime) Value() (driver.Value, error)

type NullUUID added in v0.28.0

type NullUUID struct {
	UUID  uuid.UUID
	Valid bool
}

func (*NullUUID) Scan added in v0.28.0

func (u *NullUUID) Scan(src interface{}) (err error)

func (NullUUID) Value added in v0.28.0

func (u NullUUID) Value() (driver.Value, error)

type NullUUIDArray added in v0.28.0

type NullUUIDArray struct {
	UUIDArray UUIDArray
	Valid     bool
}

func (*NullUUIDArray) Scan added in v0.28.0

func (s *NullUUIDArray) Scan(src interface{}) error

func (NullUUIDArray) Value added in v0.28.0

func (s NullUUIDArray) Value() (driver.Value, error)

type StringArray

type StringArray []string

func (*StringArray) Scan

func (s *StringArray) Scan(src interface{}) error

func (StringArray) Value

func (s StringArray) Value() (driver.Value, error)

type Tx added in v0.31.1

type Tx interface {
	Rollback(ctx context.Context) error
}

type UUIDArray

type UUIDArray []string

func (*UUIDArray) Scan

func (s *UUIDArray) Scan(src interface{}) error

func (UUIDArray) Value

func (s UUIDArray) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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