OrderBy support builder.Express
This commit is contained in:
parent
c78313e08d
commit
e2d1e0c83b
|
@ -1006,7 +1006,7 @@ func (engine *Engine) Asc(colNames ...string) *Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderBy will generate "ORDER BY order"
|
// OrderBy will generate "ORDER BY order"
|
||||||
func (engine *Engine) OrderBy(order string, args ...interface{}) *Session {
|
func (engine *Engine) OrderBy(order interface{}, args ...interface{}) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.isAutoClose = true
|
session.isAutoClose = true
|
||||||
return session.OrderBy(order, args...)
|
return session.OrderBy(order, args...)
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -17,5 +17,5 @@ require (
|
||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/ziutek/mymysql v1.5.4
|
github.com/ziutek/mymysql v1.5.4
|
||||||
modernc.org/sqlite v1.14.2
|
modernc.org/sqlite v1.14.2
|
||||||
xorm.io/builder v0.3.9
|
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -659,5 +659,5 @@ modernc.org/z v1.2.19 h1:BGyRFWhDVn5LFS5OcX4Yd/MlpRTOc7hOPTdcIpCiUao=
|
||||||
modernc.org/z v1.2.19/go.mod h1:+ZpP0pc4zz97eukOzW3xagV/lS82IpPN9NGG5pNF9vY=
|
modernc.org/z v1.2.19/go.mod h1:+ZpP0pc4zz97eukOzW3xagV/lS82IpPN9NGG5pNF9vY=
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||||
xorm.io/builder v0.3.9 h1:Sd65/LdWyO7LR8+Cbd+e7mm3sK/7U9k0jS3999IDHMc=
|
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 h1:bvLlAPW1ZMTWA32LuZMBEGHAUOcATZjzHcotf3SWweM=
|
||||||
xorm.io/builder v0.3.9/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
|
||||||
|
|
|
@ -54,7 +54,7 @@ type Interface interface {
|
||||||
Nullable(...string) *Session
|
Nullable(...string) *Session
|
||||||
Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
|
Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
|
||||||
Omit(columns ...string) *Session
|
Omit(columns ...string) *Session
|
||||||
OrderBy(order string, args ...interface{}) *Session
|
OrderBy(order interface{}, args ...interface{}) *Session
|
||||||
Ping() error
|
Ping() error
|
||||||
Query(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
|
Query(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
|
||||||
QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
|
QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
|
||||||
|
|
|
@ -33,11 +33,22 @@ func (statement *Statement) WriteOrderBy(w builder.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderBy generate "Order By order" statement
|
// OrderBy generate "Order By order" statement
|
||||||
func (statement *Statement) OrderBy(order string, args ...interface{}) *Statement {
|
func (statement *Statement) OrderBy(order interface{}, args ...interface{}) *Statement {
|
||||||
if len(statement.orderStr) > 0 {
|
if len(statement.orderStr) > 0 {
|
||||||
statement.orderStr += ", "
|
statement.orderStr += ", "
|
||||||
}
|
}
|
||||||
statement.orderStr += statement.ReplaceQuote(order)
|
var rawOrder string
|
||||||
|
switch t := order.(type) {
|
||||||
|
case (*builder.Expression):
|
||||||
|
rawOrder = t.Content()
|
||||||
|
args = t.Args()
|
||||||
|
case string:
|
||||||
|
rawOrder = t
|
||||||
|
default:
|
||||||
|
statement.LastError = ErrUnSupportedSQLType
|
||||||
|
return statement
|
||||||
|
}
|
||||||
|
statement.orderStr += statement.ReplaceQuote(rawOrder)
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
statement.orderArgs = append(statement.orderArgs, args...)
|
statement.orderArgs = append(statement.orderArgs, args...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,7 @@ func (session *Session) Limit(limit int, start ...int) *Session {
|
||||||
|
|
||||||
// OrderBy provide order by query condition, the input parameter is the content
|
// OrderBy provide order by query condition, the input parameter is the content
|
||||||
// after order by on a sql statement.
|
// after order by on a sql statement.
|
||||||
func (session *Session) OrderBy(order string, args ...interface{}) *Session {
|
func (session *Session) OrderBy(order interface{}, args ...interface{}) *Session {
|
||||||
session.statement.OrderBy(order, args...)
|
session.statement.OrderBy(order, args...)
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue