database

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFieldList = errors.New("invalid field list")
)

Database util errors

Functions

func BuildNamedParametersUpdateSetQuery

func BuildNamedParametersUpdateSetQuery(obj interface{}, fields []string) (string, error)

BuildNamedParametersUpdateSetQuery returns a string that can be used to build a set query, using named parameters (:param_name)

func BuildNamedParametersUpdateSetQueryV2

func BuildNamedParametersUpdateSetQueryV2(obj interface{}, fields []string) (string, []string, error)

BuildNamedParametersUpdateSetQueryV2 returns a string that can be used to build a set query, using named parameters (:param_name). This new version uses tag name, instead of struct's field name to compare.

func BuildParametrizedUpdateSetQuery

func BuildParametrizedUpdateSetQuery(obj interface{}, fields []string) (string, error)

BuildParametrizedUpdateSetQuery returns a string that can be used to build a set query, using parameters instead of values (parameter used is '?')

func BuildUpdateSetQuery

func BuildUpdateSetQuery(obj interface{}, fields []string) (string, error)

BuildUpdateSetQuery returns a string that can be used to build a set query, with the values put as part of the string

func GetAllFields

func GetAllFields(obj interface{}, skipFields []string, quoted bool, asNamedParameter bool) (fieldList string, err error)

GetAllFields returns all the db configured fields for the indicated struct.

Those fields indicated in 'skipFields' will not be included in the list; this is useful when dealing with auto incremental fields.

Flag 'quoted' makes all the fields to be wrapped as `field_name`; 'asNamedParameter' returns all fields as :field_name, useful for named queries. Flags are exclusive, use one or the other.

Note: those fields without the 'db' attribute or marked with a dash (`db:"-"`) are ignored.

func GetChangedFields

func GetChangedFields(original interface{}, new interface{}, skipFields []string) (fields []string, err error)

GetChangedFields compare the fieles from source and destination and returns the list of fields that have been changed

func GetParameterValues

func GetParameterValues(obj interface{}, fields []string, args ...interface{}) ([]interface{}, error)

GetParameterValues returns an array that may be used in a parametrized query

Types

type DBType

type DBType string

DBType is used to internally represent generica database types

const (
	DbTypeVarchar DBType = "VARCHAR"
	DbTypeNumeric DBType = "NUMERIC"
	DbTypeDate    DBType = "DATE"
	DbTypeBool    DBType = "BOOLEAN"
)

Database types

Jump to

Keyboard shortcuts

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