forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clause.go
56 lines (45 loc) · 925 Bytes
/
clause.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pop
import (
"fmt"
"strings"
)
type clause struct {
Fragment string
Arguments []interface{}
}
type clauses []clause
func (c clauses) Join(sep string) string {
out := make([]string, 0, len(c))
for _, clause := range c {
out = append(out, clause.Fragment)
}
return strings.Join(out, sep)
}
func (c clauses) Args() (args []interface{}) {
for _, clause := range c {
for _, arg := range clause.Arguments {
args = append(args, arg)
}
}
return
}
type fromClause struct {
From string
As string
}
type fromClauses []fromClause
func (c fromClause) String() string {
return fmt.Sprintf("%s AS %s", c.From, c.As)
}
func (c fromClauses) String() string {
cs := []string{}
for _, cl := range c {
cs = append(cs, cl.String())
}
return strings.Join(cs, ", ")
}
type belongsToThroughClause struct {
BelongsTo *Model
Through *Model
}
type belongsToThroughClauses []belongsToThroughClause