Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 8b81ff5

Browse files
committed
add support subquery on SetExpr
1 parent 57a7e44 commit 8b81ff5

13 files changed

+450
-193
lines changed

engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ func (engine *Engine) Decr(column string, arg ...interface{}) *Session {
729729
}
730730

731731
// SetExpr provides a update string like "column = {expression}"
732-
func (engine *Engine) SetExpr(column string, expression string) *Session {
732+
func (engine *Engine) SetExpr(column string, expression interface{}) *Session {
733733
session := engine.NewSession()
734734
session.isAutoClose = true
735735
return session.SetExpr(column, expression)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ require (
1616
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 // indirect
1717
github.com/stretchr/testify v1.3.0
1818
github.com/ziutek/mymysql v1.5.4
19-
xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb
19+
xorm.io/builder v0.3.6
2020
xorm.io/core v0.7.0
2121
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
162162
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
163163
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
164164
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
165-
xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb h1:2idZcp79ldX5qLeQ6WKCdS7aEFNOMvQc9wrtt5hSRwM=
166-
xorm.io/builder v0.3.6-0.20190906062455-b937eb46ecfb/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU=
165+
xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8=
166+
xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU=
167167
xorm.io/core v0.7.0 h1:hKxuOKWZNeiFQsSuGet/KV8HZ788hclvAl+7azx3tkM=
168168
xorm.io/core v0.7.0/go.mod h1:TuOJjIVa7e3w/rN8tDcAvuLBMtwzdHPbyOzE6Gk1EUI=

interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Interface interface {
5454
QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
5555
QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error)
5656
Rows(bean interface{}) (*Rows, error)
57-
SetExpr(string, string) *Session
57+
SetExpr(string, interface{}) *Session
5858
SQL(interface{}, ...interface{}) *Session
5959
Sum(bean interface{}, colName string) (float64, error)
6060
SumInt(bean interface{}, colName string) (int64, error)

session_cols.go

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,6 @@ import (
1212
"xorm.io/core"
1313
)
1414

15-
type incrParam struct {
16-
colName string
17-
arg interface{}
18-
}
19-
20-
type decrParam struct {
21-
colName string
22-
arg interface{}
23-
}
24-
25-
type exprParam struct {
26-
colName string
27-
expr string
28-
}
29-
30-
type columnMap []string
31-
32-
func (m columnMap) contain(colName string) bool {
33-
if len(m) == 0 {
34-
return false
35-
}
36-
37-
n := len(colName)
38-
for _, mk := range m {
39-
if len(mk) != n {
40-
continue
41-
}
42-
if strings.EqualFold(mk, colName) {
43-
return true
44-
}
45-
}
46-
47-
return false
48-
}
49-
50-
func (m *columnMap) add(colName string) bool {
51-
if m.contain(colName) {
52-
return false
53-
}
54-
*m = append(*m, colName)
55-
return true
56-
}
57-
5815
func setColumnInt(bean interface{}, col *core.Column, t int64) {
5916
v, err := col.ValueOf(bean)
6017
if err != nil {
@@ -132,7 +89,7 @@ func (session *Session) Decr(column string, arg ...interface{}) *Session {
13289
}
13390

13491
// SetExpr provides a query string like "column = {expression}"
135-
func (session *Session) SetExpr(column string, expression string) *Session {
92+
func (session *Session) SetExpr(column string, expression interface{}) *Session {
13693
session.statement.SetExpr(column, expression)
13794
return session
13895
}

0 commit comments

Comments
 (0)