move dir
This commit is contained in:
parent
508105d32a
commit
f8fb50999b
@ -1,4 +1,4 @@
|
||||
package structs
|
||||
package clauses
|
||||
|
||||
const (
|
||||
ExprSep = "__"
|
||||
@ -1,7 +1,7 @@
|
||||
package order
|
||||
package order_clause
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/client/orm/structs"
|
||||
"github.com/astaxie/beego/client/orm/clauses"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -57,7 +57,7 @@ func ParseOrder(expressions ...string) []*Order {
|
||||
var orders []*Order
|
||||
for _, expression := range expressions {
|
||||
sort := Ascending
|
||||
column := strings.ReplaceAll(expression, structs.ExprSep, structs.ExprDot)
|
||||
column := strings.ReplaceAll(expression, clauses.ExprSep, clauses.ExprDot)
|
||||
if column[0] == '-' {
|
||||
sort = Descending
|
||||
column = column[1:]
|
||||
@ -74,7 +74,7 @@ func ParseOrder(expressions ...string) []*Order {
|
||||
|
||||
func Column(column string) Option {
|
||||
return func(order *Order) {
|
||||
order.column = strings.ReplaceAll(column, structs.ExprSep, structs.ExprDot)
|
||||
order.column = strings.ReplaceAll(column, clauses.ExprSep, clauses.ExprDot)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package order
|
||||
package order_clause
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -16,8 +16,7 @@ package orm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/client/orm/structs"
|
||||
"github.com/astaxie/beego/client/orm/structs/clauses/order"
|
||||
"github.com/astaxie/beego/client/orm/clauses"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -423,7 +422,7 @@ func (t *dbTables) getGroupSQL(groups []string) (groupSQL string) {
|
||||
}
|
||||
|
||||
// generate order sql.
|
||||
func (t *dbTables) getOrderSQL(orders []*order.Order) (orderSQL string) {
|
||||
func (t *dbTables) getOrderSQL(orders []*order_clause.Order) (orderSQL string) {
|
||||
if len(orders) == 0 {
|
||||
return
|
||||
}
|
||||
@ -433,7 +432,7 @@ func (t *dbTables) getOrderSQL(orders []*order.Order) (orderSQL string) {
|
||||
orderSqls := make([]string, 0, len(orders))
|
||||
for _, order := range orders {
|
||||
column := order.GetColumn()
|
||||
clause := strings.Split(column, structs.ExprDot)
|
||||
clause := strings.Split(column, clauses.ExprDot)
|
||||
|
||||
if order.IsRaw() {
|
||||
if len(clause) == 2 {
|
||||
|
||||
@ -58,7 +58,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
order2 "github.com/astaxie/beego/client/orm/structs/clauses/order"
|
||||
"github.com/astaxie/beego/client/orm/clauses/order_clause"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
@ -352,7 +352,7 @@ func (o *ormBase) LoadRelatedWithCtx(ctx context.Context, md interface{}, name s
|
||||
qs.relDepth = relDepth
|
||||
|
||||
if len(order) > 0 {
|
||||
qs.orders = order2.ParseOrder(order)
|
||||
qs.orders = order_clause.ParseOrder(order)
|
||||
}
|
||||
|
||||
find := ind.FieldByIndex(fi.fieldIndex)
|
||||
|
||||
@ -16,13 +16,13 @@ package orm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/client/orm/structs"
|
||||
"github.com/astaxie/beego/client/orm/clauses"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ExprSep define the expression separation
|
||||
const (
|
||||
ExprSep = structs.ExprSep
|
||||
ExprSep = clauses.ExprSep
|
||||
)
|
||||
|
||||
type condValue struct {
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/client/orm/hints"
|
||||
"github.com/astaxie/beego/client/orm/structs/clauses/order"
|
||||
"github.com/astaxie/beego/client/orm/clauses/order_clause"
|
||||
)
|
||||
|
||||
type colValue struct {
|
||||
@ -71,7 +71,7 @@ type querySet struct {
|
||||
limit int64
|
||||
offset int64
|
||||
groups []string
|
||||
orders []*order.Order
|
||||
orders []*order_clause.Order
|
||||
distinct bool
|
||||
forUpdate bool
|
||||
useIndex int
|
||||
@ -143,12 +143,12 @@ func (o querySet) OrderBy(expressions ...string) QuerySeter {
|
||||
if len(expressions) <= 0 {
|
||||
return &o
|
||||
}
|
||||
o.orders = order.ParseOrder(expressions...)
|
||||
o.orders = order_clause.ParseOrder(expressions...)
|
||||
return &o
|
||||
}
|
||||
|
||||
// add ORDER expression.
|
||||
func (o querySet) OrderClauses(orders ...*order.Order) QuerySeter {
|
||||
func (o querySet) OrderClauses(orders ...*order_clause.Order) QuerySeter {
|
||||
if len(orders) <= 0 {
|
||||
return &o
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/client/orm/structs/clauses/order"
|
||||
"github.com/astaxie/beego/client/orm/clauses/order_clause"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
@ -1080,9 +1080,9 @@ func TestOrderBy(t *testing.T) {
|
||||
throwFail(t, AssertIs(num, 1))
|
||||
|
||||
num, err = qs.OrderClauses(
|
||||
order.Clause(
|
||||
order.Column(`profile__age`),
|
||||
order.SortDescending(),
|
||||
order_clause.Clause(
|
||||
order_clause.Column(`profile__age`),
|
||||
order_clause.SortDescending(),
|
||||
),
|
||||
).Filter("user_name", "astaxie").Count()
|
||||
throwFail(t, err)
|
||||
@ -1090,9 +1090,9 @@ func TestOrderBy(t *testing.T) {
|
||||
|
||||
if IsMysql {
|
||||
num, err = qs.OrderClauses(
|
||||
order.Clause(
|
||||
order.Column(`rand()`),
|
||||
order.Raw(),
|
||||
order_clause.Clause(
|
||||
order_clause.Column(`rand()`),
|
||||
order_clause.Raw(),
|
||||
),
|
||||
).Filter("user_name", "astaxie").Count()
|
||||
throwFail(t, err)
|
||||
@ -1185,9 +1185,9 @@ func TestValues(t *testing.T) {
|
||||
}
|
||||
|
||||
num, err = qs.OrderClauses(
|
||||
order.Clause(
|
||||
order.Column("Id"),
|
||||
order.SortAscending(),
|
||||
order_clause.Clause(
|
||||
order_clause.Column("Id"),
|
||||
order_clause.SortAscending(),
|
||||
),
|
||||
).Values(&maps)
|
||||
throwFail(t, err)
|
||||
|
||||
@ -17,7 +17,7 @@ package orm
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"github.com/astaxie/beego/client/orm/structs/clauses/order"
|
||||
"github.com/astaxie/beego/client/orm/clauses/order_clause"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@ -293,25 +293,25 @@ type QuerySeter interface {
|
||||
// add ORDER expression by order clauses
|
||||
// for example:
|
||||
// OrderClauses(
|
||||
// order.Clause(
|
||||
// order_clause.Clause(
|
||||
// order.Column("Id"),
|
||||
// order.SortAscending(),
|
||||
// ),
|
||||
// order.Clause(
|
||||
// order_clause.Clause(
|
||||
// order.Column("status"),
|
||||
// order.SortDescending(),
|
||||
// ),
|
||||
// )
|
||||
// OrderClauses(order.Clause(
|
||||
// order.Column(`user__status`),
|
||||
// order.SortDescending(),//default None
|
||||
// OrderClauses(order_clause.Clause(
|
||||
// order_clause.Column(`user__status`),
|
||||
// order_clause.SortDescending(),//default None
|
||||
// ))
|
||||
// OrderClauses(order.Clause(
|
||||
// order.Column(`random()`),
|
||||
// order.SortNone(),//default None
|
||||
// order.Raw(),//default false.if true, do not check field is valid or not
|
||||
// OrderClauses(order_clause.Clause(
|
||||
// order_clause.Column(`random()`),
|
||||
// order_clause.SortNone(),//default None
|
||||
// order_clause.Raw(),//default false.if true, do not check field is valid or not
|
||||
// ))
|
||||
OrderClauses(orders ...*order.Order) QuerySeter
|
||||
OrderClauses(orders ...*order_clause.Order) QuerySeter
|
||||
// add FORCE INDEX expression.
|
||||
// for example:
|
||||
// qs.ForceIndex(`idx_name1`,`idx_name2`)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user