2016-06-15 00:01:28 +10:00
|
|
|
package qm
|
2016-04-13 23:51:58 +10:00
|
|
|
|
2016-08-09 17:59:30 +10:00
|
|
|
import "github.com/vattle/sqlboiler/boil"
|
2016-04-13 23:51:58 +10:00
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// QueryMod to modify the query object
|
2016-04-19 12:02:32 +10:00
|
|
|
type QueryMod func(q *boil.Query)
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// Apply the query mods to the Query object
|
2016-04-20 22:51:04 +10:00
|
|
|
func Apply(q *boil.Query, mods ...QueryMod) {
|
|
|
|
for _, mod := range mods {
|
|
|
|
mod(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// SQL allows you to execute a plain SQL statement
|
|
|
|
func SQL(sql string, args ...interface{}) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetSQL(q, sql, args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit the number of returned rows
|
2016-04-19 15:31:07 +10:00
|
|
|
func Limit(limit int) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetLimit(q, limit)
|
2016-04-13 23:51:58 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 19:21:06 -07:00
|
|
|
// Offset into the results
|
|
|
|
func Offset(offset int) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetOffset(q, offset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// InnerJoin on another table
|
2016-08-07 13:37:51 -07:00
|
|
|
func InnerJoin(clause string, args ...interface{}) QueryMod {
|
2016-04-19 15:31:07 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-07 18:12:13 -07:00
|
|
|
boil.AppendInnerJoin(q, clause, args...)
|
2016-04-19 15:31:07 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// Select specific columns opposed to all columns
|
2016-04-16 17:25:00 +10:00
|
|
|
func Select(columns ...string) QueryMod {
|
2016-04-19 12:02:32 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-03 22:22:17 -07:00
|
|
|
boil.AppendSelect(q, columns...)
|
2016-04-16 17:25:00 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// Where allows you to specify a where clause for your statement
|
2016-04-13 23:51:58 +10:00
|
|
|
func Where(clause string, args ...interface{}) QueryMod {
|
2016-04-19 12:02:32 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-03 22:22:17 -07:00
|
|
|
boil.AppendWhere(q, clause, args...)
|
2016-04-13 23:51:58 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 16:44:15 +10:00
|
|
|
// And allows you to specify a where clause seperated by an AND for your statement
|
|
|
|
// And is a duplicate of the Where function, but allows for more natural looking
|
|
|
|
// query mod chains, for example: (Where("a=?"), And("b=?"), Or("c=?")))
|
|
|
|
func And(clause string, args ...interface{}) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.AppendWhere(q, clause, args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Or allows you to specify a where clause seperated by an OR for your statement
|
|
|
|
func Or(clause string, args ...interface{}) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetLastWhereAsOr(q)
|
|
|
|
boil.AppendWhere(q, clause, args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// GroupBy allows you to specify a group by clause for your statement
|
2016-04-13 23:51:58 +10:00
|
|
|
func GroupBy(clause string) QueryMod {
|
2016-04-19 12:02:32 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-03 22:22:17 -07:00
|
|
|
boil.ApplyGroupBy(q, clause)
|
2016-04-13 23:51:58 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// OrderBy allows you to specify a order by clause for your statement
|
2016-04-13 23:51:58 +10:00
|
|
|
func OrderBy(clause string) QueryMod {
|
2016-04-19 12:02:32 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-03 22:22:17 -07:00
|
|
|
boil.ApplyOrderBy(q, clause)
|
2016-04-13 23:51:58 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// Having allows you to specify a having clause for your statement
|
2016-08-13 03:08:09 +10:00
|
|
|
func Having(clause string, args ...interface{}) QueryMod {
|
2016-04-19 12:02:32 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-13 03:08:09 +10:00
|
|
|
boil.ApplyHaving(q, clause, args...)
|
2016-04-13 23:51:58 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:07:12 +10:00
|
|
|
// From allows to specify the table for your statement
|
|
|
|
func From(from string) QueryMod {
|
2016-04-19 12:02:32 +10:00
|
|
|
return func(q *boil.Query) {
|
2016-08-03 22:22:17 -07:00
|
|
|
boil.AppendFrom(q, from)
|
2016-04-13 23:51:58 +10:00
|
|
|
}
|
|
|
|
}
|
2016-08-06 15:10:35 -07:00
|
|
|
|
|
|
|
// Count turns the query into a counting calculation
|
|
|
|
func Count() QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetCount(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avg turns the query into an average calculation
|
|
|
|
func Avg() QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetAvg(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Min turns the query into a minimum calculation
|
|
|
|
func Min() QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetMin(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Max turns the query into a maximum calculation
|
|
|
|
func Max() QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetMax(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sum turns the query into a sum calculation
|
|
|
|
func Sum() QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetSum(q)
|
|
|
|
}
|
|
|
|
}
|