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