-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstructor.go
62 lines (48 loc) · 1.29 KB
/
constructor.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
57
58
59
60
61
62
package parser
import (
"fmt"
"github.com/Masterminds/squirrel"
)
// Parser exposes the Go
type Parser interface {
Go(string) (squirrel.Sqlizer, error)
}
// New constructor
func New(Str func(search string) squirrel.Sqlizer) Parser {
p := &parser2{
Str: Str,
StrORStr: func(a, b string) squirrel.Or {
return squirrel.Or{Str(a), Str(b)}
},
ExpORStr: func(a squirrel.Sqlizer, b string) squirrel.Or {
return squirrel.Or{a, Str(b)}
},
StrORExp: func(a string, b squirrel.Sqlizer) squirrel.Or {
return squirrel.Or{Str(a), b}
},
ExpORExp: func(a, b squirrel.Sqlizer) squirrel.Or {
return squirrel.Or{a, b}
},
StrANDStr: func(a, b string) squirrel.And {
return squirrel.And{Str(a), Str(b)}
},
ExpANDStr: func(a squirrel.Sqlizer, b string) squirrel.And {
return squirrel.And{a, Str(b)}
},
StrANDExp: func(a string, b squirrel.Sqlizer) squirrel.And {
return squirrel.And{Str(a), b}
},
ExpANDExp: func(a, b squirrel.Sqlizer) squirrel.And {
return squirrel.And{a, b}
},
NotStr: func(a string) squirrel.Sqlizer {
s, v, _ := Str(a).ToSql()
return squirrel.Expr(fmt.Sprintf("NOT (%s)", s), v...)
},
NotExp: func(a squirrel.Sqlizer) squirrel.Sqlizer {
s, v, _ := a.ToSql()
return squirrel.Expr(fmt.Sprintf("NOT (%s)", s), v...)
},
}
return p
}