sqlutil

package
v0.0.0-...-c6ea6ab Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: LGPL-3.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNoRowsInResultSet                = errutil.NewFactory("no rows in result set")
	ErrorDuplicateViolateUniqueConstraint = errutil.NewFactory("duplicate key value violates unique constraint")
	ErrorTsquerySyntax                    = errutil.NewFactory("syntax error in tsquery")
)

errors

View Source
var (
	ErrorPrepareNamed  = errutil.NewFactory("prepare SQL named query failed")
	ErrorNoRowAffected = errutil.NewFactory("no row affected")
)

errors

View Source
var (
	ErrorUnsupportedScanType1 = errutil.NewFactory("unsupported scan type: %T")
	ErrorInvalidObjType1      = errutil.NewFactory("invalid obj type: %T")
	ErrorNoValueFound1        = errutil.NewFactory("no value found for key %v")
)

errors

Functions

func IsContainErrorDuplicateViolateUniqueConstraint

func IsContainErrorDuplicateViolateUniqueConstraint(err error) bool

IsContainErrorDuplicateViolateUniqueConstraint check err contain sql error "duplicate key value violates unique constraint"

func IsContainErrorNoRowsInResultSet

func IsContainErrorNoRowsInResultSet(err error) bool

IsContainErrorNoRowsInResultSet check err contain sql error "no rows in result set"

func IsContainErrorTsquerySyntax

func IsContainErrorTsquerySyntax(err error) bool

IsContainErrorTsquerySyntax check error contain sql error "syntax error in tsquery"

func IsErrorDuplicateViolateUniqueConstraint

func IsErrorDuplicateViolateUniqueConstraint(err error) bool

IsErrorDuplicateViolateUniqueConstraint check err is sql error "duplicate key value violates unique constraint"

func IsErrorNoRowsInResultSet

func IsErrorNoRowsInResultSet(err error) bool

IsErrorNoRowsInResultSet check err is sql error "no rows in result set" or "no row affected"

func IsErrorTsquerySyntax

func IsErrorTsquerySyntax(err error) bool

IsErrorTsquerySyntax check error is sql error "syntax error in tsquery"

func NamedExecContext

func NamedExecContext(
	ctx context.Context,
	tx dbtypes.Named,
	query string,
	arg interface{},
) (result sql.Result, err error)

NamedExecContext prepare named SQL statement and call Exec function with context

func NamedExecStrictContext

func NamedExecStrictContext(
	ctx context.Context,
	tx dbtypes.Named,
	query string,
	arg interface{},
) (result sql.Result, err error)

NamedExecStrictContext like NamedExecContext, but result rows affected should greater than zero

func NamedGetContext

func NamedGetContext(
	ctx context.Context,
	tx dbtypes.Named,
	dest interface{},
	query string,
	arg interface{},
) (err error)

NamedGetContext prepare named SQL statement and call Get function with context, return error if get nothing

func NamedSelectContext

func NamedSelectContext(
	ctx context.Context,
	tx dbtypes.Named,
	dest interface{},
	query string,
	arg interface{},
) (err error)

NamedSelectContext prepare named SQL statement and call Select function with context

func NamedSelectInContext

func NamedSelectInContext(
	ctx context.Context,
	tx dbtypes.Transactionx,
	dest interface{},
	query string,
	arg interface{},
) (err error)

NamedSelectInContext prepare named/in SQL statement and call Select function with context

func NamedSelectInStrictContext

func NamedSelectInStrictContext(
	ctx context.Context,
	tx dbtypes.Transactionx,
	dest interface{},
	query string,
	arg interface{},
) (err error)

NamedSelectInStrictContext prepare named/in SQL statement and call Select function with context, return error if select nothing

func NamedSelectStrictContext

func NamedSelectStrictContext(
	ctx context.Context,
	tx dbtypes.Named,
	dest interface{},
	query string,
	arg interface{},
) (err error)

NamedSelectStrictContext prepare named SQL statement and call Select function with context, return error if select nothing

func ParseTsQuery

func ParseTsQuery(ctx context.Context, tx *sqlx.DB, query string) (result string, err error)

ParseTsQuery remove invalid tsquery syntax, tx should not be transaction because error will cause transaction stop

func SQLScanEnumString

func SQLScanEnumString(obj interface{}, value interface{}, stringMapEnum map[string]interface{}) (err error)

SQLScanEnumString set obj to value's enum in stringMapEnum representation

func SQLScanJSON

func SQLScanJSON(obj interface{}, value interface{}) (err error)

SQLScanJSON set obj to value's JSON representation

func SQLScanStrictJSON

func SQLScanStrictJSON(obj interface{}, value interface{}) (err error)

SQLScanStrictJSON set obj to value's JSON representation, all field should exist in obj

func SQLScanString

func SQLScanString(obj interface{}, value interface{}) (err error)

SQLScanString set obj to value's string representation

func SQLScanStringSlice

func SQLScanStringSlice(obj interface{}, value interface{}) (err error)

SQLScanStringSlice set obj to value's stringslice representation

func SQLValueJSON

func SQLValueJSON(obj interface{}) (value driver.Value, err error)

SQLValueJSON return obj's JSON representation which implements driver.Value

func SQLValueStringSlice

func SQLValueStringSlice(obj interface{}) (value driver.Value, err error)

SQLValueStringSlice return s postgresql representation which implements driver.Value

Types

type SQLJsonMap

type SQLJsonMap map[string]interface{}

SQLJsonMap general map type for SQL

func (*SQLJsonMap) Scan

func (t *SQLJsonMap) Scan(value interface{}) (err error)

Scan decode SQL value

func (SQLJsonMap) Value

func (t SQLJsonMap) Value() (value driver.Value, err error)

Value return data for SQL

type SQLNullTime

type SQLNullTime struct {
	pq.NullTime
}

SQLNullTime represents a time.Time that may be null. Inherit pq.NullTime and rewrite JSON marshaler

func (SQLNullTime) MarshalJSON

func (t SQLNullTime) MarshalJSON() ([]byte, error)

MarshalJSON implement JSON marshaler

func (*SQLNullTime) UnmarshalJSON

func (t *SQLNullTime) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implement JSON unmarshaler

type SQLStringSlice

type SQLStringSlice []string

SQLStringSlice is a type of []string and implement SQL driver

func NewSQLStringSlice

func NewSQLStringSlice(s *[]string) *SQLStringSlice

NewSQLStringSlice create from *[]string

func (*SQLStringSlice) Scan

func (t *SQLStringSlice) Scan(value interface{}) (err error)

Scan decode SQL value

func (*SQLStringSlice) ToStringSlice

func (t *SQLStringSlice) ToStringSlice() *[]string

ToStringSlice return nil if SQLStringSlice is nil

func (SQLStringSlice) Value

func (t SQLStringSlice) Value() (value driver.Value, err error)

Value return data for SQL

type SQLStringSliceJSON

type SQLStringSliceJSON []string

SQLStringSliceJSON is a type of []string and implement SQL driver

func (*SQLStringSliceJSON) Scan

func (t *SQLStringSliceJSON) Scan(value interface{}) (err error)

Scan decode SQL value

func (SQLStringSliceJSON) Value

func (t SQLStringSliceJSON) Value() (value driver.Value, err error)

Value return data for SQL

type SQLUUID

type SQLUUID string

SQLUUID autogenerated raml type

func (*SQLUUID) Scan

func (t *SQLUUID) Scan(value interface{}) (err error)

Scan decode SQL value to UUID

func (SQLUUID) Value

func (t SQLUUID) Value() (v driver.Value, err error)

Value return UUID data for SQL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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