Documentation ¶
Index ¶
- func CreatePeggedAssocFields(db *gorm.DB, modelObj models.IModel) (err error)
- func DeleteModelFixManyToManyAndPegAndPegAssoc(db *gorm.DB, modelObj models.IModel) error
- func DesignatorContainsDot(rel *PredicateRelation) bool
- func FindFieldNameToStructAndStructFieldNameIfAny(rel *PredicateRelation) (*string, *string)
- func GetOuterTableName(modelObj models.IModel, fieldNameDesignator string) (string, error)
- type BatchCreateData
- type BuilderInfo
- type Criteria
- type Escape
- type IQuery
- type ModelAndBuilder
- type Predicate
- func (p *Predicate) BuildQueryStringAndValues(modelObj models.IModel) (string, []interface{}, error)
- func (p *Predicate) GetAllUnqueStructFieldDesignator() map[string]interface{}
- func (p *Predicate) GetDesignatedField(modelObj models.IModel) string
- func (p *Predicate) GetDesignatedModel(modelObj models.IModel) (models.IModel, error)
- func (p *Predicate) GetNestedLevel() int
- type PredicateCond
- type PredicateLogic
- type PredicateRelation
- func (pr *PredicateRelation) BuildQueryStringAndValues(modelObj models.IModel) (string, []interface{}, error)
- func (pr *PredicateRelation) GetAllUnqueStructFieldDesignator() map[string]interface{}
- func (pr *PredicateRelation) GetDesignatedField(modelObj models.IModel) string
- func (pr *PredicateRelation) GetDesignatedModel(modelObj models.IModel) (models.IModel, error)
- func (pr *PredicateRelation) GetNestedLevel() int
- type PredicateRelationBuilder
- func (p *PredicateRelationBuilder) And(args ...interface{}) *PredicateRelationBuilder
- func (p *PredicateRelationBuilder) C(args ...interface{}) *PredicateRelationBuilder
- func (p *PredicateRelationBuilder) GetPredicateRelation() (*PredicateRelation, error)
- func (p *PredicateRelationBuilder) Or(args ...interface{}) *PredicateRelationBuilder
- type Query
- func (q *Query) BuildQuery(modelObj models.IModel) (*gorm.DB, error)
- func (q *Query) Count(modelObj models.IModel, no *int) IQuery
- func (q *Query) Create(modelObj models.IModel) IQuery
- func (q *Query) CreateMany(modelObjs []models.IModel) IQuery
- func (q *Query) Delete(modelObj models.IModel) IQuery
- func (q *Query) DeleteMany(modelObjs []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) GetDB() *gorm.DB
- func (q *Query) GetDBOri() *gorm.DB
- 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(modelObj models.IModel, p *PredicateRelationBuilder) IQuery
- type QueryType
- type TableAndArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreatePeggedAssocFields ¶ added in v0.5.1
CreatePeggedAssocFields :-
func DeleteModelFixManyToManyAndPegAndPegAssoc ¶ added in v0.5.1
func DesignatorContainsDot ¶ added in v0.4.50
func DesignatorContainsDot(rel *PredicateRelation) bool
func FindFieldNameToStructAndStructFieldNameIfAny ¶
func FindFieldNameToStructAndStructFieldNameIfAny(rel *PredicateRelation) (*string, *string)
hacky...
Types ¶
type BatchCreateData ¶ added in v0.5.1
type BatchCreateData struct {
// contains filtered or unexported fields
}
type BuilderInfo ¶ added in v0.4.50
type BuilderInfo struct {
// contains filtered or unexported fields
}
type Criteria ¶
type Criteria interface { BuildQueryStringAndValues(modelObj models.IModel) (string, []interface{}, error) // GetDesignatedModel gets the inner model within this modelObj designated by the criteria // If it's on the first-level, modelObj itself is returned GetDesignatedModel(modelObj models.IModel) (models.IModel, error) // GetDesignatedField gets the name of the current Field designator for the inner model // or empty string if it is modelObj itself GetDesignatedField(modelObj models.IModel) string // GetAllUnqueStructFieldDesignator returns the struct fields designators (used for buliding joins within // nested table). For example, A.B.C returns A.B. and A. // Returns map because what we really want is a unique set. The value of the map is not important. GetAllUnqueStructFieldDesignator() map[string]interface{} // GetNestedLevel is the level the criteria designates // The top-most level is 1 GetNestedLevel() int }
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 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 BuildQuery(modelObj models.IModel) (*gorm.DB, error) First(modelObj models.IModel) IQuery Find(modelObjs interface{}) IQuery Count(modelObj models.IModel, no *int) IQuery Create(modelObj models.IModel) IQuery CreateMany(modelObjs []models.IModel) IQuery Delete(modelObj models.IModel) IQuery DeleteMany(modelObjs []models.IModel) IQuery Save(modelObj models.IModel) IQuery // Update(modelObjs interface{}, attrs ...interface{}) IQuery Update(modelObj models.IModel, p *PredicateRelationBuilder) IQuery GetDB() *gorm.DB GetDBOri() *gorm.DB Reset() IQuery Error() error }
IQuery so we can stubb out the DB
type ModelAndBuilder ¶
type ModelAndBuilder struct {
// contains filtered or unexported fields
}
func (*ModelAndBuilder) GetAllPotentialJoinStructDesignators ¶ added in v0.4.50
func (mb *ModelAndBuilder) GetAllPotentialJoinStructDesignators() ([]string, error)
func (*ModelAndBuilder) SortBuilderInfosByLevel ¶ added in v0.4.50
func (mb *ModelAndBuilder) SortBuilderInfosByLevel()
top level table has to be joined before more-nested table are joined
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
func (*Predicate) GetAllUnqueStructFieldDesignator ¶ added in v0.4.50
func (*Predicate) GetDesignatedField ¶ added in v0.4.47
func (*Predicate) GetDesignatedModel ¶ added in v0.4.47
func (*Predicate) GetNestedLevel ¶ added in v0.4.50
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" // PredicateCondBETWEEN is between two values PredicateCondBETWEEN PredicateCond = "BETWEEN" )
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)
func (*PredicateRelation) GetAllUnqueStructFieldDesignator ¶ added in v0.4.50
func (pr *PredicateRelation) GetAllUnqueStructFieldDesignator() map[string]interface{}
GetAllUnqueStructFieldDesignator returns all unique designators which are struct field Example: Dogs.DogToy.Name, Dogs.DogToy.Color, Name, furniture.Type will return Dogs.DogToy, Furniture This function is needed to figure out the join statement we need to issue
func (*PredicateRelation) GetDesignatedField ¶ added in v0.4.47
func (pr *PredicateRelation) GetDesignatedField(modelObj models.IModel) string
func (*PredicateRelation) GetDesignatedModel ¶ added in v0.4.47
func (*PredicateRelation) GetNestedLevel ¶ added in v0.4.50
func (pr *PredicateRelation) GetNestedLevel() int
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 NewPredicateRelationBuilder ¶ added in v0.5.7
func NewPredicateRelationBuilder() *PredicateRelationBuilder
func (*PredicateRelationBuilder) And ¶
func (p *PredicateRelationBuilder) And(args ...interface{}) *PredicateRelationBuilder
s is Name =?, v is value
func (*PredicateRelationBuilder) C ¶
func (p *PredicateRelationBuilder) C(args ...interface{}) *PredicateRelationBuilder
func (*PredicateRelationBuilder) GetPredicateRelation ¶
func (p *PredicateRelationBuilder) GetPredicateRelation() (*PredicateRelation, error)
func (*PredicateRelationBuilder) Or ¶
func (p *PredicateRelationBuilder) Or(args ...interface{}) *PredicateRelationBuilder
s is Name =?, v is value
type Query ¶
type Query struct { // args []interface{} Err error // 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
func (*Query) BuildQuery ¶ added in v0.5.7
This is a passover for building query, we're just building the where clause
func (*Query) CreateMany ¶ added in v0.5.1
func (*Query) Delete ¶ added in v0.4.37
Delete can be with criteria, or can just delete the model directly
func (*Query) DeleteMany ¶ added in v0.5.1
func (*Query) InnerJoin ¶
func (q *Query) InnerJoin(modelObj models.IModel, foreignObj models.IModel, args ...interface{}) IQuery
args can be multiple C(), each C() works on one-level of modelObj The args are to select the query of modelObj designated, it could work on nested level inside the modelObj assuming first is top-level, if given.
type TableAndArgs ¶
type TableAndArgs struct { TblName string // The table the predicate relation applies to, at this level (non-nested) Args []interface{} }