Documentation ¶
Index ¶
- func Union(queries ...*Q) (string, error)
- type Column
- type IModel
- type OrderDir
- type Q
- func (q *Q) Alias(alias string) *Q
- func (q *Q) Count(name Column, as string) *Q
- func (q *Q) Field(name Column) *Q
- func (q *Q) FieldAs(name Column, as string) *Q
- func (q *Q) FieldRaw(fieldStr, as string) *Q
- func (q *Q) Fields(fields ...string) *Q
- func (q *Q) Limit(limit, offset int64) *Q
- func (q *Q) OrderBy(col Column, dir OrderDir) *Q
- func (q *Q) Raw(query string) *Q
- func (q *Q) Set(fieldName Column, value interface{}) *Q
- func (q *Q) String() (string, error)
- func (q *Q) Sum(name Column, as string) *Q
- func (q *Q) Where(args ...*WherePart) *Q
- type QueryType
- type TableName
- type WherePart
- func And(args ...*WherePart) *WherePart
- func Ands(args ...*WherePart) *WherePart
- func Between(fieldName Column, from, to interface{}) *WherePart
- func BitAnd(fieldName Column, a, b int64) *WherePart
- func EQ(fieldName Column, value interface{}) *WherePart
- func EQF(fieldName1, fieldName2 string) *WherePart
- func Exists(clause *Q) *WherePart
- func GT(fieldName Column, value interface{}) *WherePart
- func GTOE(fieldName Column, value interface{}) *WherePart
- func IN(fieldName Column, values ...interface{}) *WherePart
- func INInt64(fieldName Column, values []int64) *WherePart
- func INString(fieldName Column, values []string) *WherePart
- func LT(fieldName Column, value interface{}) *WherePart
- func LTOE(fieldName Column, value interface{}) *WherePart
- func Like(fieldName Column, value string) *WherePart
- func Mod(fieldName Column, value, remainder int64) *WherePart
- func Modf(value int64, fieldName Column, remainder int64) *WherePart
- func NE(fieldName Column, value interface{}) *WherePart
- func NOTIN(fieldName Column, values ...interface{}) *WherePart
- func NotLike(fieldName Column, value string) *WherePart
- func Or(args ...*WherePart) *WherePart
- func Ors(args ...*WherePart) *WherePart
- func PE() *WherePart
- func PS() *WherePart
- func Paren(args ...*WherePart) *WherePart
- func Rawf(str string, args ...interface{}) *WherePart
- func WhereAll() *WherePart
- type WhereType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type IModel ¶
type IModel interface { Table_Name() TableName Table_Columns() []Column Table_PrimaryKey() Column Table_PrimaryKey_Value() int64 Table_InsertColumns() []Column Table_UpdateColumns() []Column Table_Column_Types() map[Column]string String() string Update(db db.IDB) error Create(db db.IDB) error Delete(db db.IDB) error FromID(db db.IDB, id int64) (IModel, error) }
type Q ¶
type Q struct {
// contains filtered or unexported fields
}
func (*Q) FieldAs ¶
FieldAs includes a specific field in the columns to be returned by a set aliased by `as`
type WherePart ¶
type WherePart struct {
// contains filtered or unexported fields
}
WherePart is a part of a where clause. This object is an exposed part of the api to make conditional queries easier EXAMPLE:
wheres := []query.WherePart{ query.EQ(models.ObjectRelationship_Column_IsDeleted, 0), } if objectTypeFrom != constants.ObjectTypeUnknown { wheres = append(wheres, query.And(), query.EQ(models.ObjectRelationship_Column_ObjectTypeFrom, objectTypeFrom)) } if objectIDFrom > 0 { wheres = append(wheres, query.And(), query.EQ(models.ObjectRelationship_Column_ObjectIDFrom, objectIDFrom)) }
func And ¶
And is an and statement with optional args that, if provided, are wrapped in parentheses Example: And() will result in the word `AND` being added to the where clause Example: And(EQ(1, 1), And(), And(2, 2)) will result in `AND ( 1 = 1 AND 2 = 2 )`
func Ands ¶ added in v1.8.45
Ands takes a list of args and separes them all by `AND` Example: Ands(query.EQ(1,1), query.EQ(2,2), query.EQ(3,3)) == 1 = 1 AND 2 = 2 AND 3 = 3
func INInt64 ¶ added in v1.8.15
INInt64 is a helper function for converting a slice of string arguments into a slice of interface arguments, passed into an IN clause and returned
func INString ¶ added in v1.8.15
INString is a helper function for converting a slice of string arguments into a slice of interface arguments, passed into an IN clause and returned
type WhereType ¶
type WhereType int
const ( WhereTypeEquals WhereType = iota WhereTypeEqualsField WhereTypeNotEquals WhereTypeGreaterThan WhereTypeLessThan WhereTypeGreaterThanOrEqualTo WhereTypeLessThanOrEqualTo WhereTypeBetween WhereTypeLike WhereTypeNotLike WhereTypeIN WhereTypeNotIN WhereTypeExists WhereTypeAnd WhereTypeOr WhereTypeParenthesisEnd WhereTypeParenthesisStart // WhereTypeNone indicates that the wherePart is a noop for the query, // If, however, it contains any child clauses, they will be parsed as individual wherePart objects WhereTypeNone // WhereTypeAll is a WHERE clause of `1=1` used for convenience // when conditionally adding WHERE clauses starting with a conjunction (AND/OR,etc) // separating them. // e.g. SELECT * FROM `Foo` WHERE 1=1 // SELECT * FROM `Foo` WHERE 1=1 AND FooID = 123; WhereTypeAll WhereTypeMod WhereTypeModF WhereTypeBitAnd WhereTypeRaw )