Method In provides a update string
This commit is contained in:
parent
38616e71fd
commit
97f4b0e45c
|
@ -342,6 +342,11 @@ func (engine *Engine) In(column string, args ...interface{}) *Session {
|
|||
session := engine.NewSession()
|
||||
session.IsAutoClose = true
|
||||
return session.In(column, args...)
|
||||
// Method In provides a update string like "column = column + ?"
|
||||
func (engine *Engine) Inc(column string, arg interface{}) *Session {
|
||||
session := engine.NewSession()
|
||||
session.IsAutoClose = true
|
||||
return session.Inc(column, arg)
|
||||
}
|
||||
|
||||
// Temporarily change the Get, Find, Update's table
|
||||
|
|
12
session.go
12
session.go
|
@ -128,6 +128,12 @@ func (session *Session) In(column string, args ...interface{}) *Session {
|
|||
return session
|
||||
}
|
||||
|
||||
// Method In provides a query string like "count = count + 1"
|
||||
func (session *Session) Inc(column string, arg interface{}) *Session {
|
||||
session.Statement.Inc(column, arg)
|
||||
return session
|
||||
}
|
||||
|
||||
// Method Cols provides some columns to special
|
||||
func (session *Session) Cols(columns ...string) *Session {
|
||||
session.Statement.Cols(columns...)
|
||||
|
@ -2952,6 +2958,12 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
args = append(args, time.Now())
|
||||
}
|
||||
|
||||
//for update action to like "column = column + ?"
|
||||
incColumns := session.Statement.getInc()
|
||||
for k, v := range incColumns {
|
||||
colNames = append(colNames, k+" = "+k+" + ?")
|
||||
args = append(args, v)
|
||||
}
|
||||
var condiColNames []string
|
||||
var condiArgs []interface{}
|
||||
|
||||
|
|
12
statement.go
12
statement.go
|
@ -48,6 +48,7 @@ type Statement struct {
|
|||
checkVersion bool
|
||||
mustColumnMap map[string]bool
|
||||
inColumns map[string]*inParam
|
||||
incColumns map[string]interface{}
|
||||
}
|
||||
|
||||
// init
|
||||
|
@ -470,6 +471,17 @@ func (statement *Statement) Id(id interface{}) *Statement {
|
|||
return statement
|
||||
}
|
||||
|
||||
// Generate "Update ... Set column = column + arg" statment
|
||||
func (statement *Statement) Inc(column string, arg interface{}) *Statement {
|
||||
k := strings.ToLower(column)
|
||||
statement.incColumns[k] = arg
|
||||
return statement
|
||||
}
|
||||
|
||||
// Generate "Update ... Set column = column + arg" statment
|
||||
func (statement *Statement) getInc() map[string]interface{} {
|
||||
return statement.incColumns
|
||||
}
|
||||
// Generate "Where column IN (?) " statment
|
||||
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||
k := strings.ToLower(column)
|
||||
|
|
Loading…
Reference in New Issue