@@ -12,10 +12,51 @@ type Changer struct {
12
12
values Values
13
13
}
14
14
15
+ // Modifier changes a value for update statement
16
+ type Modifier func (v interface {}) interface {}
17
+
18
+ // IncrInt returns a modifier for int/int8/int16/int32/int64 increment
19
+ func IncrInt (to interface {}) Modifier {
20
+ return func (v interface {}) interface {} {
21
+ if x , ok := v .(int ); ok {
22
+ return x + to .(int )
23
+ }
24
+ if x , ok := v .(int8 ); ok {
25
+ return x + to .(int8 )
26
+ }
27
+ if x , ok := v .(int16 ); ok {
28
+ return x + to .(int16 )
29
+ }
30
+ if x , ok := v .(int32 ); ok {
31
+ return x + to .(int32 )
32
+ }
33
+ if x , ok := v .(int64 ); ok {
34
+ return x + to .(int64 )
35
+ }
36
+ panic ("y/update: unknown int type for increment." )
37
+ }
38
+ }
39
+
40
+ // IncrFloat returns a modifier for float32/float64 increment
41
+ func IncrFloat (to interface {}) Modifier {
42
+ return func (v interface {}) interface {} {
43
+ if x , ok := v .(float32 ); ok {
44
+ return x + to .(float32 )
45
+ }
46
+ if x , ok := v .(float64 ); ok {
47
+ return x + to .(float64 )
48
+ }
49
+ panic ("y/update: unknown float type for increment." )
50
+ }
51
+ }
52
+
15
53
func (c * Changer ) modify () sq.Eq {
16
54
modified := sq.Eq {}
17
55
for name , val := range c .values {
18
56
f := c .proxy .Field (name )
57
+ if modifier , ok := val .(Modifier ); ok {
58
+ val = modifier (f .Interface ())
59
+ }
19
60
if f .Interface () != val {
20
61
modified [name ] = val
21
62
f .Set (reflect .ValueOf (val ))
0 commit comments