pgutil

package
v1.1.35 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrUnknown is returned for all errors with unknown cause.
	ErrUnknown = iota

	// ErrUniqueViolation is returned for unique constraint violations.
	ErrUniqueViolation

	// ErrNotNullViolation is returned for non-null constraint violations.
	ErrNotNullViolation

	// ErrRecordNotFound is returned when query is expected to return a single record, but none are returned.
	ErrRecordNotFound

	// ErrInvalidText is returned when you try assigned invalid value to types such as uuid.
	ErrInvalidText
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*gorm.DB
}

Client is a wrapper for *gorm.DB providing a handy Close() function.

func DialPostgres

func DialPostgres(c *config.Config) (*Client, error)

DialPostgres creates a connection to Postgres using values from specified config.Config, and returns Client instance.

func (*Client) Close

func (c *Client) Close()

Close closes a connection to Postgres.

type Error

type Error struct {
	// Err is the wrapped error.
	Err error

	// Code is the error code.
	Code int

	// Constraint is the name of violated constraint.
	Constraint string

	// TableName is the name of the table.
	TableName string

	// ColumnName is the name of the column.
	ColumnName string

	// Message is the message returned by the DB.
	Message string
}

Error represents a wrapped query error.

func TranslateError

func TranslateError(err error) *Error

TranslateError tries to cast given error instance to PgError and extract enough information to build Error instance.

Jump to

Keyboard shortcuts

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