dbutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package dbutil provides database related utilities

Index

Constants

View Source
const (
	// Class 22 - Data Exception
	PqDataException             pq.ErrorClass = "22000"
	PqInvalidTextRepresentation pq.ErrorCode  = "22P02"

	// Class 23 — Integrity Constraint Violation
	ErrIntegrityConstraintViolation pq.ErrorClass = "23000"
	ErrNotNullViolation             pq.ErrorCode  = "23502"
	ErrForeignKeyViolation          pq.ErrorCode  = "23503"
	ErrUniqueViolation              pq.ErrorCode  = "23505"
	ErrCheckViolation               pq.ErrorCode  = "23514"
)

Variables

This section is empty.

Functions

func InterpolateSql

func InterpolateSql(query string, args ...interface{}) string

func RebindPlaceholders

func RebindPlaceholders(query string) string

Replaces all MySQL-style '?,?,...' placeholders with Postgres-style '$1,$2,...' placeholders.

Types

type DBError

type DBError struct {
	Code   pq.ErrorCode
	Query  string
	Err    error
	Detail string
	Hint   string
}

func AsDBError

func AsDBError(err error) (*DBError, bool)

func NewDBError

func NewDBError(err error, query string, args ...interface{}) *DBError

NewDBError decorates an error returned from the database with the relevant query that was used (in (*DBError).Query so that handler functions can print out which SQL query was responsible for causing the error. If the underlying error is a (*pq.Error), it also copies the Code, Detail and Hint fields from

func (*DBError) Error

func (e *DBError) Error() string

func (*DBError) Unwrap

func (e *DBError) Unwrap() error

Jump to

Keyboard shortcuts

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