-
Notifications
You must be signed in to change notification settings - Fork 5
/
exprmysql.go
53 lines (46 loc) · 1008 Bytes
/
exprmysql.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
//go:build !tinygo.wasm
package sqlla
import (
"github.com/go-sql-driver/mysql"
)
type ExprMysqlNullTime struct {
Column string
Value mysql.NullTime
Op Operator
}
func (e ExprMysqlNullTime) ToSql() (string, []interface{}, error) {
var ops, placeholder string
var err error
vs := []interface{}{}
if !e.Value.Valid {
if e.Op == OpNot {
ops, err = opIsNotNull.ToSql()
} else {
ops, err = opIsNull.ToSql()
}
} else {
ops, err = e.Op.ToSql()
placeholder = " ?"
vs = append(vs, e.Value)
}
if err != nil {
return "", nil, err
}
return e.Column + " " + ops + placeholder, vs, nil
}
type ExprMultiMysqlNullTime struct {
Column string
Values []mysql.NullTime
Op Operator
}
func (e ExprMultiMysqlNullTime) ToSql() (string, []interface{}, error) {
ops, err := e.Op.ToSql()
if err != nil {
return "", nil, err
}
vs := make([]interface{}, 0, len(e.Values))
for _, v := range e.Values {
vs = append(vs, interface{}(v))
}
return e.Column + " " + ops, vs, nil
}