github.com/RevenueMonster/sqlike@v1.0.6/sqlike/actions/update.go (about) 1 package actions 2 3 import ( 4 "github.com/RevenueMonster/sqlike/sql/expr" 5 "github.com/RevenueMonster/sqlike/sqlike/primitive" 6 ) 7 8 // UpdateStatement : 9 type UpdateStatement interface { 10 Where(fields ...interface{}) UpdateStatement 11 Set(values ...primitive.KV) UpdateStatement 12 OrderBy(fields ...interface{}) UpdateStatement 13 Limit(num uint) UpdateStatement 14 } 15 16 // UpdateActions : 17 type UpdateActions struct { 18 Database string 19 Table string 20 Conditions []interface{} 21 Values []primitive.KV 22 Sorts []interface{} 23 Record uint 24 } 25 26 // Where : 27 func (act *UpdateActions) Where(fields ...interface{}) UpdateStatement { 28 act.Conditions = expr.And(fields...).Values 29 return act 30 } 31 32 // Set : 33 func (act *UpdateActions) Set(values ...primitive.KV) UpdateStatement { 34 act.Values = append(act.Values, values...) 35 return act 36 } 37 38 // OrderBy : 39 func (act *UpdateActions) OrderBy(fields ...interface{}) UpdateStatement { 40 act.Sorts = fields 41 return act 42 } 43 44 // Limit : 45 func (act *UpdateActions) Limit(num uint) UpdateStatement { 46 if num > 0 { 47 act.Record = num 48 } 49 return act 50 }