forked from sabrinalua/simple-sql-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditions.go
48 lines (41 loc) · 911 Bytes
/
conditions.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
package helper
import "fmt"
// Condition ...
type Condition struct {
named bool
Key string
Operator string
Value interface{}
}
// ConditionEqual ///
func ConditionEqual(key string, value interface{}) *Condition {
return &Condition{
Key: key,
Value: value,
Operator: "=",
}
}
// ConditionLessThan ...
func ConditionLessThan(key string, value interface{}) *Condition {
return &Condition{
Key: key,
Value: value,
Operator: "<",
}
}
// ConditionNotEqual ///
func ConditionNotEqual(key string, value interface{}) *Condition {
return &Condition{
Key: key,
Value: value,
Operator: "!=",
}
}
func (me *Condition) string(i ...int) string {
if len(i) > 0 {
// key=:named_value
return fmt.Sprintf("%v%v:%v", me.Key, me.Operator, i[0])
}
//key=?
return fmt.Sprintf("%v%v?", me.Key, me.Operator)
}