forked from si3nloong/sqlike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
50 lines (43 loc) · 1.04 KB
/
update.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
package actions
import (
"github.com/RevenueMonster/sqlike/sql/expr"
"github.com/RevenueMonster/sqlike/sqlike/primitive"
)
// UpdateStatement :
type UpdateStatement interface {
Where(fields ...interface{}) UpdateStatement
Set(values ...primitive.KV) UpdateStatement
OrderBy(fields ...interface{}) UpdateStatement
Limit(num uint) UpdateStatement
}
// UpdateActions :
type UpdateActions struct {
Database string
Table string
Conditions []interface{}
Values []primitive.KV
Sorts []interface{}
Record uint
}
// Where :
func (act *UpdateActions) Where(fields ...interface{}) UpdateStatement {
act.Conditions = expr.And(fields...).Values
return act
}
// Set :
func (act *UpdateActions) Set(values ...primitive.KV) UpdateStatement {
act.Values = append(act.Values, values...)
return act
}
// OrderBy :
func (act *UpdateActions) OrderBy(fields ...interface{}) UpdateStatement {
act.Sorts = fields
return act
}
// Limit :
func (act *UpdateActions) Limit(num uint) UpdateStatement {
if num > 0 {
act.Record = num
}
return act
}