sqlutil

package
v0.0.0-...-0aebffb Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMarkerWhere

func AddMarkerWhere(
	qs *string,
	opts *pb.SearchOptions,
	alias string,
	includeAnd bool,
	qargs *[]interface{},
	infos []*SortFieldInfo,
	markerLookup func() string,
)

Examines the supplied search options and injects a WHERE clause that filters a page of results based on a marker value and the sort direction requested. The DB field we winnow is always the uuid field (which is what the marker contains.

func AddOrderBy

func AddOrderBy(qs *string, opts *pb.SearchOptions, alias string)

Extends the supplied raw SQL string with an ORDER BY clause based on a pb.SearchOptions message and a table alias

func InParamString

func InParamString(numArgs int) string

Returns a string containing the expression IN with one or more question marks for parameter interpolation. If numArgs argument is 3, the returned value would be "IN (?, ?, ?)"

func IsDuplicateKey

func IsDuplicateKey(err error) bool

Returns true if the supplied error represents a duplicate key error

func IsDuplicateKeyOn

func IsDuplicateKeyOn(err error, constraintName string) bool

Returns true if the supplied error is a duplicate key error and the supplied constraint name is the one that was violated

func NormalizeSortFields

func NormalizeSortFields(
	opts *pb.SearchOptions,
	sortFieldInfos *[]*SortFieldInfo,
) error

Looks through any requested sort fields and validates that the sort field is something we can sort on, replacing any aliases with the correct database field name. Returns an error if any requested sort field isn't valid.

func Ping

func Ping(db *sql.DB, connectTimeout time.Duration) error

Attempts to connect to the backend IAM database. Uses an exponential backoff retry strategy so that this can be run early in a service's startup code and we will wait for DB connectivity to materialize if not there initially.

Types

type SortFieldInfo

type SortFieldInfo struct {
	Name    string
	Unique  bool
	Aliases []string
}

Jump to

Keyboard shortcuts

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