Remove bad things (sum, min, max, avg, etc)
This commit is contained in:
parent
2179570afd
commit
26bb719563
4 changed files with 24 additions and 124 deletions
|
@ -136,38 +136,3 @@ func Offset(offset int) QueryMod {
|
|||
boil.SetOffset(q, offset)
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,22 +18,22 @@ const (
|
|||
|
||||
// Query holds the state for the built up query
|
||||
type Query struct {
|
||||
executor Executor
|
||||
plainSQL plainSQL
|
||||
load []string
|
||||
delete bool
|
||||
update map[string]interface{}
|
||||
selectCols []string
|
||||
modFunction string
|
||||
from []string
|
||||
joins []join
|
||||
where []where
|
||||
in []in
|
||||
groupBy []string
|
||||
orderBy []string
|
||||
having []having
|
||||
limit int
|
||||
offset int
|
||||
executor Executor
|
||||
plainSQL plainSQL
|
||||
load []string
|
||||
delete bool
|
||||
update map[string]interface{}
|
||||
selectCols []string
|
||||
count bool
|
||||
from []string
|
||||
joins []join
|
||||
where []where
|
||||
in []in
|
||||
groupBy []string
|
||||
orderBy []string
|
||||
having []having
|
||||
limit int
|
||||
offset int
|
||||
}
|
||||
|
||||
type where struct {
|
||||
|
@ -121,27 +121,7 @@ func SetLoad(q *Query, relationships ...string) {
|
|||
|
||||
// SetCount on the query.
|
||||
func SetCount(q *Query) {
|
||||
q.modFunction = "COUNT"
|
||||
}
|
||||
|
||||
// SetAvg on the query.
|
||||
func SetAvg(q *Query) {
|
||||
q.modFunction = "AVG"
|
||||
}
|
||||
|
||||
// SetMax on the query.
|
||||
func SetMax(q *Query) {
|
||||
q.modFunction = "MAX"
|
||||
}
|
||||
|
||||
// SetMin on the query.
|
||||
func SetMin(q *Query) {
|
||||
q.modFunction = "MIN"
|
||||
}
|
||||
|
||||
// SetSum on the query.
|
||||
func SetSum(q *Query) {
|
||||
q.modFunction = "SUM"
|
||||
q.count = true
|
||||
}
|
||||
|
||||
// SetDelete on the query.
|
||||
|
|
|
@ -41,15 +41,13 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
|
|||
|
||||
buf.WriteString("SELECT ")
|
||||
|
||||
// Wrap the select in the modifier function
|
||||
hasModFunc := len(q.modFunction) != 0
|
||||
if hasModFunc {
|
||||
fmt.Fprintf(buf, "%s(", q.modFunction)
|
||||
if q.count {
|
||||
buf.WriteString("COUNT(")
|
||||
}
|
||||
|
||||
hasSelectCols := len(q.selectCols) != 0
|
||||
hasJoins := len(q.joins) != 0
|
||||
if hasSelectCols && hasJoins && !hasModFunc {
|
||||
if hasJoins && hasSelectCols && !q.count {
|
||||
selectColsWithAs := writeAsStatements(q)
|
||||
// Don't identQuoteSlice - writeAsStatements does this
|
||||
buf.WriteString(strings.Join(selectColsWithAs, ", "))
|
||||
|
@ -62,7 +60,8 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
|
|||
buf.WriteByte('*')
|
||||
}
|
||||
|
||||
if hasModFunc {
|
||||
// close SQL COUNT function
|
||||
if q.count {
|
||||
buf.WriteByte(')')
|
||||
}
|
||||
|
||||
|
|
|
@ -296,52 +296,8 @@ func TestSetCount(t *testing.T) {
|
|||
q := &Query{}
|
||||
SetCount(q)
|
||||
|
||||
if q.modFunction != "COUNT" {
|
||||
t.Errorf("Wrong modFunction, got %s", q.modFunction)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetAvg(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := &Query{}
|
||||
SetAvg(q)
|
||||
|
||||
if q.modFunction != "AVG" {
|
||||
t.Errorf("Wrong modFunction, got %s", q.modFunction)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetMax(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := &Query{}
|
||||
SetMax(q)
|
||||
|
||||
if q.modFunction != "MAX" {
|
||||
t.Errorf("Wrong modFunction, got %s", q.modFunction)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetMin(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := &Query{}
|
||||
SetMin(q)
|
||||
|
||||
if q.modFunction != "MIN" {
|
||||
t.Errorf("Wrong modFunction, got %s", q.modFunction)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetSum(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := &Query{}
|
||||
SetSum(q)
|
||||
|
||||
if q.modFunction != "SUM" {
|
||||
t.Errorf("Wrong modFunction, got %s", q.modFunction)
|
||||
if q.count != true {
|
||||
t.Errorf("got false")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue