-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinsert.go
More file actions
42 lines (34 loc) · 686 Bytes
/
insert.go
File metadata and controls
42 lines (34 loc) · 686 Bytes
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
package mogi
import (
"fmt"
"reflect"
"strings"
"github.com/guregu/mogi/internal/sqlparser"
)
type insertCond struct {
cols []string
}
func (ic insertCond) matches(in input) bool {
_, ok := in.statement.(*sqlparser.Insert)
if !ok {
return false
}
// zero parameters means anything
if len(ic.cols) == 0 {
return true
}
return reflect.DeepEqual(lowercase(ic.cols), lowercase(in.cols()))
}
func (ic insertCond) priority() int {
if len(ic.cols) > 0 {
return 2
}
return 1
}
func (ic insertCond) String() string {
cols := "(any)" // TODO support star select
if len(ic.cols) > 0 {
cols = strings.Join(ic.cols, ", ")
}
return fmt.Sprintf("INSERT %s", cols)
}