dbutil

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: AGPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BulkQuery

func BulkQuery[T any](ctx context.Context, tx Queryer, query string, structs []T) error

BulkQuery runs the query as a bulk operation with the given structs

func BulkSQL

func BulkSQL[T any](tx Queryer, sql string, structs []T) (string, []interface{}, error)

BulkSQL takes a query which uses VALUES with struct bindings and rewrites it as a bulk operation. It returns the new SQL query and the args to pass to it.

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation returns true if the given error is a violation of unique constraint

func NewQueryErrorf

func NewQueryErrorf(cause error, sql string, sqlArgs []interface{}, message string, msgArgs ...interface{}) error

func ScanAndValidateJSON

func ScanAndValidateJSON(rows *sqlx.Rows, destination interface{}) error

ScanAndValidateJSON scans a row which is JSON into a destination struct and validates it

func ScanJSON

func ScanJSON(rows *sqlx.Rows, destination interface{}) error

ScanJSON scans a row which is JSON into a destination struct

Types

type QueryError

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

QueryError is an error type for failed SQL queries

func AsQueryError

func AsQueryError(err error) *QueryError

func (*QueryError) Error

func (e *QueryError) Error() string

func (*QueryError) Query

func (e *QueryError) Query() (string, []interface{})

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

type Queryer

type Queryer interface {
	Rebind(query string) string
	QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
}

Queryer is the DB/TX functionality needed for operations in this package

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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