Documentation ¶
Index ¶
- func FieldNameToColumn(modelObj models.IModel, fieldName string) (string, error)
- func FindFieldNameToStructAndStructFieldNameIfAny(rel *PredicateRelation) (*string, *string)
- func GetInnerModelIfValid(modelObj models.IModel, field string) (models.IModel, error)
- func GetModelFieldTypeInModelIfValid(modelObj models.IModel, field string) (reflect.Type, error)
- func IsFieldInModel(modelObj models.IModel, field string) bool
- func JSONKeysToFieldName(modelObj models.IModel, key string) (string, error)
- type Criteria
- type Escape
- type FieldNotInModelError
- type IQuery
- type ModelAndBuilder
- type Predicate
- type PredicateCond
- type PredicateLogic
- type PredicateRelation
- type PredicateRelationBuilder
- func (p *PredicateRelationBuilder) And(s string, v interface{}) *PredicateRelationBuilder
- func (p *PredicateRelationBuilder) BuildQueryStringAndValues(model models.IModel) (string, []interface{}, error)
- func (p *PredicateRelationBuilder) C(s string, v interface{}) *PredicateRelationBuilder
- func (p *PredicateRelationBuilder) GetPredicateRelation() (*PredicateRelation, error)
- func (p *PredicateRelationBuilder) Or(s string, v interface{}) *PredicateRelationBuilder
- type Query
- func (q *Query) Create(modelObj models.IModel) IQuery
- func (q *Query) Delete(modelObj models.IModel) IQuery
- func (q *Query) Error() error
- func (q *Query) Find(modelObjs interface{}) IQuery
- func (q *Query) First(modelObj models.IModel) IQuery
- func (q *Query) InnerJoin(modelObj models.IModel, foreignObj models.IModel, args ...interface{}) IQuery
- func (q *Query) Limit(limit int) IQuery
- func (q *Query) Offset(offset int) IQuery
- func (q *Query) Order(order string) IQuery
- func (q *Query) Q(args ...interface{}) IQuery
- func (q *Query) Reset() IQuery
- func (q *Query) Save(modelObj models.IModel) IQuery
- func (q *Query) Update(attrs ...interface{}) IQuery
- type QueryType
- type TableAndArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldNameToColumn ¶
func FindFieldNameToStructAndStructFieldNameIfAny ¶
func FindFieldNameToStructAndStructFieldNameIfAny(rel *PredicateRelation) (*string, *string)
hacky...
func GetInnerModelIfValid ¶
func GetModelFieldTypeInModelIfValid ¶
Never returns the pointer value Since what we want is reflec.New() and it would be a pointer
Types ¶
type Escape ¶
type Escape struct {
Value string
}
If a predicte value is wrapped within an Escape class Assume it has a Stringer interface, and the result of the string is not wrapped in quotes as Postgres values, and also SQL injection is not checked So this should only be used internally
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 IQuery ¶ added in v0.4.39
type IQuery interface { Q(args ...interface{}) IQuery Order(order string) IQuery Limit(limit int) IQuery Offset(offset int) IQuery InnerJoin(modelObj models.IModel, foreignObj models.IModel, args ...interface{}) IQuery First(modelObj models.IModel) IQuery Find(modelObjs interface{}) IQuery Create(modelObj models.IModel) IQuery Delete(modelObj models.IModel) IQuery Save(modelObj models.IModel) IQuery Update(attrs ...interface{}) IQuery Reset() IQuery Error() error }
IQuery so we can stubb out the DB
type ModelAndBuilder ¶
type ModelAndBuilder struct { ModelObj models.IModel // THe model this predicate relation applies to Builder *PredicateRelationBuilder }
type Predicate ¶
type Predicate struct { Field string // e.g. Age Cond PredicateCond // e.g. <, or IN Value interface{} // e.g. 20 or an array of values }
Predicate is used to represent something like Age < 20
func NewPredicateFromStringAndVal ¶
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) BuildQueryStringAndValues ¶
func (p *Predicate) BuildQueryStringAndValues(modelObj models.IModel) (string, []interface{}, error)
BuildQuryStringAndValues output proper query conditionals and the correponding values which field those fields Because this then is given to the database, the output needs to match the column names
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 = ">=" // PredicateCondGTEQ is greater than or equal to PredicateCondIN PredicateCond = "IN" )
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 PredOrRels []Criteria 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) A Criteria is a Predicate or Predicate relation Every nested PredicateRelation is meant to work on one models.IModel. It can also designate criteria for nested class. But it cannot be used for another unrelated Model where there is no nesting relationships.
func NewPredicateRelation ¶
func NewPredicateRelation() *PredicateRelation
func (*PredicateRelation) BuildQueryStringAndValues ¶
func (pr *PredicateRelation) BuildQueryStringAndValues(modelObj models.IModel) (string, []interface{}, error)
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
args is either two arguments: "Name =" "Christy", or another predicate builder C()
func (*PredicateRelationBuilder) And ¶
func (p *PredicateRelationBuilder) And(s string, v interface{}) *PredicateRelationBuilder
s is Name =?, v is value
func (*PredicateRelationBuilder) BuildQueryStringAndValues ¶
func (p *PredicateRelationBuilder) BuildQueryStringAndValues(model models.IModel) (string, []interface{}, error)
func (*PredicateRelationBuilder) C ¶
func (p *PredicateRelationBuilder) C(s string, v interface{}) *PredicateRelationBuilder
s is Name =?, v is value
func (*PredicateRelationBuilder) GetPredicateRelation ¶
func (p *PredicateRelationBuilder) GetPredicateRelation() (*PredicateRelation, error)
func (*PredicateRelationBuilder) Or ¶
func (p *PredicateRelationBuilder) Or(s string, v interface{}) *PredicateRelationBuilder
s is Name =?, v is value
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Q is the query struct Q(db).By("Name IN", []strings{name1, name2}, "Age >=", 18).Find(&model).Error This is a wrapper over Gorm's. Query by field name, and prevent SQL injection by making sure that fields are part of the model
type TableAndArgs ¶
type TableAndArgs struct { TblName string // The table the predicate relation applies to, at this level (non-nested) Args []interface{} }