query

package
v0.4.35 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByID

func ByID(tx *gorm.DB, modelObj models.IModel, id *datatypes.UUID) error

func FindByPredicateRelation

func FindByPredicateRelation(tx *gorm.DB, modelObjs []models.IModel, pr *PredicateRelation) error

func FirstByFieldQueries

func FirstByFieldQueries(tx *gorm.DB, modelObj models.IModel, args ...interface{}) error

FirstByFieldQueries query the model by query string and values args are "name =", "Christy", "age >=", 30 for example

func FirstByPredicateRelation

func FirstByPredicateRelation(tx *gorm.DB, modelObj models.IModel, pr *PredicateRelation) error

func GetModelFieldTypeIfValid

func GetModelFieldTypeIfValid(modelObj models.IModel, fieldName string) (reflect.Type, error)

func GetModelFieldTypeInModelIfValid

func GetModelFieldTypeInModelIfValid(modelObj models.IModel, field string) (reflect.Type, error)

Never returns the pointer value Since what we want is reflec.New() and it would be a pointer

func IsFieldInModel

func IsFieldInModel(modelObj models.IModel, field string) bool

Types

type FieldNotInModelError

type FieldNotInModelError struct {
	Msg string
}

FieldNotInModelError is for GetModelFieldTypeIfValid. if field doesn't exist in the model, return this error We want to go ahead and skip it since this field may be other options that user can read in hookpoints

func (*FieldNotInModelError) Error

func (r *FieldNotInModelError) Error() string

type Predicate

type Predicate struct {
	Field string        // e.g. age
	Cond  PredicateCond // e.g. <
	Value interface{}   // e.g. 20
}

Predicate is used to represent something like age < 20

func NewPredicateFromStringAndVal

func NewPredicateFromStringAndVal(s string, value interface{}) (*Predicate, error)

NewPredicateFromStringAndVal, turn string like "age <" and value into proper predicate This is for convenience I cannot get "age < 20" directly because I'd have to know in advance the type of object (unless of course I just send it as a string, wonder if SQL can take it)

func (*Predicate) BuildQueryStringAndValue

func (p *Predicate) BuildQueryStringAndValue() (string, interface{})

type PredicateCond

type PredicateCond string
const (
	// PredicateCondEQ is equals
	PredicateCondEQ PredicateCond = "="
	// PredicateCondLT is less than
	PredicateCondLT PredicateCond = "<"
	// PredicateCondLTEQ is less than or equal to
	PredicateCondLTEQ PredicateCond = "<="
	// PredicateCondGT is equal to
	PredicateCondGT PredicateCond = ">"
	// PredicateCondGTEQ is greater than or equal to
	PredicateCondGTEQ PredicateCond = ">="
)

func StringToPredicateCond

func StringToPredicateCond(s string) (PredicateCond, error)

type PredicateLogic

type PredicateLogic string
const (
	PredicateLogicAND PredicateLogic = "AND"
	PredicateLogicOR  PredicateLogic = "OR"
)

type PredicateRelation

type PredicateRelation struct {
	// PredOrRel contains either be a *Predicate or *PredicateRelation
	// If PredicateRelation than it is nested comparison
	PredOrRel []interface{}
	Logics    []PredicateLogic // AND or OR. The number of Logic operators is one less than the number of predicates
}

PredicateRelation represents things like (age < 20 OR age > 70 OR age = 30) Or it can contain other relations (age < 20 AND (name = "Timothy" OR name = "Christy") by compositing another relations

func NewPredicateRelation

func NewPredicateRelation() *PredicateRelation

func (*PredicateRelation) BuildQueryStringAndValues

func (pr *PredicateRelation) BuildQueryStringAndValues() (string, []interface{})

type PredicateRelationBuilder

type PredicateRelationBuilder struct {
	Rel   *PredicateRelation
	Error error // This allow us to chain and eventually discover any error by querying for Error
}

func C

func C(args ...interface{}) *PredicateRelationBuilder

func C(s string, v interface{}) *PredicateRelationBuilder {

func NewPredicateRelationBuilder added in v0.5.7

func NewPredicateRelationBuilder() *PredicateRelationBuilder

func (*PredicateRelationBuilder) And

func (p *PredicateRelationBuilder) And(s string, v interface{}) *PredicateRelationBuilder

func (*PredicateRelationBuilder) BuildQueryStringAndValues

func (p *PredicateRelationBuilder) BuildQueryStringAndValues() (string, []interface{}, error)

func (*PredicateRelationBuilder) C

func (*PredicateRelationBuilder) GetPredicateRelation

func (p *PredicateRelationBuilder) GetPredicateRelation() (*PredicateRelation, error)

func (*PredicateRelationBuilder) Or

func (p *PredicateRelationBuilder) Or(s string, v interface{}) *PredicateRelationBuilder

type QueryType

type QueryType int
const (
	QueryTypeFirst QueryType = iota
	QueryTypeFind  QueryType = iota
)

Jump to

Keyboard shortcuts

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