dbutil

package
v1.53.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 10 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, db BulkQueryer, query string, structs []T) error

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

func BulkSQL

func BulkSQL[T any](db BulkQueryer, sql string, structs []T) (string, []any, 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 QueryErrorWrapf added in v1.41.2

func QueryErrorWrapf(cause error, sql string, sqlArgs []any, message string, msgArgs ...any) error

func QueryErrorf added in v1.41.2

func QueryErrorf(sql string, sqlArgs []any, message string, msgArgs ...any) error

func ScanAllJSON added in v1.41.3

func ScanAllJSON[V any](rows *sql.Rows, s []V) ([]V, error)

ScanAllJSON scans all rows as a single column containing JSON that be unmarshalled into instances of V.

func ScanAllMap added in v1.39.0

func ScanAllMap[K comparable, V any](rows *sql.Rows, m map[K]V) error

ScanAllMap scans a key and value from each two column row into the given map

func ScanAllSlice added in v1.39.0

func ScanAllSlice[V any](rows *sql.Rows, s []V) ([]V, error)

ScanAllSlice scans all rows as a single value and returns them in the given slice.

func ScanAndValidateJSON

func ScanAndValidateJSON(rows *sql.Rows, destination any) error

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

func ScanJSON

func ScanJSON(rows *sql.Rows, destination any) error

ScanJSON scans a row which is JSON into a destination struct

func ToValidUTF8 added in v1.33.0

func ToValidUTF8(s string) string

ToValidUTF8 replaces invalid UTF-8 sequences with � characters and also strips NULL characters, which whilst being valid UTF-8, can't be saved to PostgreSQL.

Types

type BulkQueryer added in v1.39.1

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

BulkQueryer is the DB/TX functionality needed for these bulk operations

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, []any)

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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