2016-06-14 16:01:28 +02:00
|
|
|
package qm
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-06-08 07:45:34 +02:00
|
|
|
import "github.com/nullbio/sqlboiler/boil"
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// QueryMod to modify the query object
|
2016-04-19 04:02:32 +02:00
|
|
|
type QueryMod func(q *boil.Query)
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// Apply the query mods to the Query object
|
2016-04-20 14:51:04 +02:00
|
|
|
func Apply(q *boil.Query, mods ...QueryMod) {
|
|
|
|
for _, mod := range mods {
|
|
|
|
mod(q)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02: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...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Or surrounds where clauses to join them with OR as opposed to AND
|
2016-06-02 23:07:51 +02:00
|
|
|
func Or(whereMods ...QueryMod) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
if len(whereMods) < 2 {
|
2016-07-19 06:07:12 +02:00
|
|
|
panic("Or requires at least two arguments")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, w := range whereMods {
|
|
|
|
w(q)
|
|
|
|
boil.SetLastWhereAsOr(q)
|
2016-06-02 23:07:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// Limit the number of returned rows
|
2016-04-19 07:31:07 +02:00
|
|
|
func Limit(limit int) QueryMod {
|
|
|
|
return func(q *boil.Query) {
|
|
|
|
boil.SetLimit(q, limit)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// InnerJoin on another table
|
2016-07-19 07:36:26 +02:00
|
|
|
func InnerJoin(stmt string, args ...interface{}) QueryMod {
|
2016-04-19 07:31:07 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-07-19 07:36:26 +02:00
|
|
|
boil.SetInnerJoin(q, stmt, args...)
|
2016-04-19 07:31:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// OuterJoin on another table
|
2016-07-19 07:36:26 +02:00
|
|
|
func OuterJoin(stmt string, args ...interface{}) QueryMod {
|
2016-04-19 07:31:07 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-07-19 07:36:26 +02:00
|
|
|
boil.SetOuterJoin(q, stmt, args...)
|
2016-04-19 07:31:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// LeftOuterJoin on another table
|
2016-07-19 07:36:26 +02:00
|
|
|
func LeftOuterJoin(stmt string, args ...interface{}) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-07-19 07:36:26 +02:00
|
|
|
boil.SetLeftOuterJoin(q, stmt, args...)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// RightOuterJoin on another table
|
2016-07-19 07:36:26 +02:00
|
|
|
func RightOuterJoin(stmt string, args ...interface{}) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-07-19 07:36:26 +02:00
|
|
|
boil.SetRightOuterJoin(q, stmt, args...)
|
2016-04-16 09:25:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// Select specific columns opposed to all columns
|
2016-04-16 09:25:00 +02:00
|
|
|
func Select(columns ...string) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-04-19 07:31:07 +02:00
|
|
|
boil.SetSelect(q, columns...)
|
2016-04-16 09:25:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// Where allows you to specify a where clause for your statement
|
2016-04-13 15:51:58 +02:00
|
|
|
func Where(clause string, args ...interface{}) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-04-19 07:31:07 +02:00
|
|
|
boil.SetWhere(q, clause, args...)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// GroupBy allows you to specify a group by clause for your statement
|
2016-04-13 15:51:58 +02:00
|
|
|
func GroupBy(clause string) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-04-19 07:31:07 +02:00
|
|
|
boil.SetGroupBy(q, clause)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// OrderBy allows you to specify a order by clause for your statement
|
2016-04-13 15:51:58 +02:00
|
|
|
func OrderBy(clause string) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-04-19 07:31:07 +02:00
|
|
|
boil.SetOrderBy(q, clause)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// Having allows you to specify a having clause for your statement
|
2016-04-13 15:51:58 +02:00
|
|
|
func Having(clause string) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-04-19 07:31:07 +02:00
|
|
|
boil.SetHaving(q, clause)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:07:12 +02:00
|
|
|
// From allows to specify the table for your statement
|
|
|
|
func From(from string) QueryMod {
|
2016-04-19 04:02:32 +02:00
|
|
|
return func(q *boil.Query) {
|
2016-07-19 06:07:12 +02:00
|
|
|
boil.SetFrom(q, from)
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
}
|