Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
59b92c03
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
59b92c03
编写于
11月 07, 2020
作者:
M
Ming Deng
提交者:
GitHub
11月 07, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4279 from jianzhiyao/frt/supports_for_4144
supports_for_4144
上级
20a0de6b
f864e585
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
352 addition
and
18 deletion
+352
-18
client/orm/clauses/const.go
client/orm/clauses/const.go
+6
-0
client/orm/clauses/order_clause/order.go
client/orm/clauses/order_clause/order.go
+103
-0
client/orm/clauses/order_clause/order_test.go
client/orm/clauses/order_clause/order_test.go
+144
-0
client/orm/db_tables.go
client/orm/db_tables.go
+20
-12
client/orm/orm.go
client/orm/orm.go
+2
-1
client/orm/orm_conds.go
client/orm/orm_conds.go
+2
-1
client/orm/orm_queryset.go
client/orm/orm_queryset.go
+16
-4
client/orm/orm_test.go
client/orm/orm_test.go
+34
-0
client/orm/types.go
client/orm/types.go
+23
-0
task/task.go
task/task.go
+2
-0
未找到文件。
client/orm/clauses/const.go
0 → 100644
浏览文件 @
59b92c03
package
clauses
const
(
ExprSep
=
"__"
ExprDot
=
"."
)
client/orm/clauses/order_clause/order.go
0 → 100644
浏览文件 @
59b92c03
package
order_clause
import
(
"github.com/astaxie/beego/client/orm/clauses"
"strings"
)
type
Sort
int8
const
(
None
Sort
=
0
Ascending
Sort
=
1
Descending
Sort
=
2
)
type
Option
func
(
order
*
Order
)
type
Order
struct
{
column
string
sort
Sort
isRaw
bool
}
func
Clause
(
options
...
Option
)
*
Order
{
o
:=
&
Order
{}
for
_
,
option
:=
range
options
{
option
(
o
)
}
return
o
}
func
(
o
*
Order
)
GetColumn
()
string
{
return
o
.
column
}
func
(
o
*
Order
)
GetSort
()
Sort
{
return
o
.
sort
}
func
(
o
*
Order
)
SortString
()
string
{
switch
o
.
GetSort
()
{
case
Ascending
:
return
"ASC"
case
Descending
:
return
"DESC"
}
return
``
}
func
(
o
*
Order
)
IsRaw
()
bool
{
return
o
.
isRaw
}
func
ParseOrder
(
expressions
...
string
)
[]
*
Order
{
var
orders
[]
*
Order
for
_
,
expression
:=
range
expressions
{
sort
:=
Ascending
column
:=
strings
.
ReplaceAll
(
expression
,
clauses
.
ExprSep
,
clauses
.
ExprDot
)
if
column
[
0
]
==
'-'
{
sort
=
Descending
column
=
column
[
1
:
]
}
orders
=
append
(
orders
,
&
Order
{
column
:
column
,
sort
:
sort
,
})
}
return
orders
}
func
Column
(
column
string
)
Option
{
return
func
(
order
*
Order
)
{
order
.
column
=
strings
.
ReplaceAll
(
column
,
clauses
.
ExprSep
,
clauses
.
ExprDot
)
}
}
func
sort
(
sort
Sort
)
Option
{
return
func
(
order
*
Order
)
{
order
.
sort
=
sort
}
}
func
SortAscending
()
Option
{
return
sort
(
Ascending
)
}
func
SortDescending
()
Option
{
return
sort
(
Descending
)
}
func
SortNone
()
Option
{
return
sort
(
None
)
}
func
Raw
()
Option
{
return
func
(
order
*
Order
)
{
order
.
isRaw
=
true
}
}
client/orm/clauses/order_clause/order_test.go
0 → 100644
浏览文件 @
59b92c03
package
order_clause
import
(
"testing"
)
func
TestClause
(
t
*
testing
.
T
)
{
var
(
column
=
`a`
)
o
:=
Clause
(
Column
(
column
),
)
if
o
.
GetColumn
()
!=
column
{
t
.
Error
()
}
}
func
TestSortAscending
(
t
*
testing
.
T
)
{
o
:=
Clause
(
SortAscending
(),
)
if
o
.
GetSort
()
!=
Ascending
{
t
.
Error
()
}
}
func
TestSortDescending
(
t
*
testing
.
T
)
{
o
:=
Clause
(
SortDescending
(),
)
if
o
.
GetSort
()
!=
Descending
{
t
.
Error
()
}
}
func
TestSortNone
(
t
*
testing
.
T
)
{
o1
:=
Clause
(
SortNone
(),
)
if
o1
.
GetSort
()
!=
None
{
t
.
Error
()
}
o2
:=
Clause
()
if
o2
.
GetSort
()
!=
None
{
t
.
Error
()
}
}
func
TestRaw
(
t
*
testing
.
T
)
{
o1
:=
Clause
()
if
o1
.
IsRaw
()
{
t
.
Error
()
}
o2
:=
Clause
(
Raw
(),
)
if
!
o2
.
IsRaw
()
{
t
.
Error
()
}
}
func
TestColumn
(
t
*
testing
.
T
)
{
o1
:=
Clause
(
Column
(
`aaa`
),
)
if
o1
.
GetColumn
()
!=
`aaa`
{
t
.
Error
()
}
}
func
TestParseOrder
(
t
*
testing
.
T
)
{
orders
:=
ParseOrder
(
`-user__status`
,
`status`
,
`user__status`
,
)
t
.
Log
(
orders
)
if
orders
[
0
]
.
GetSort
()
!=
Descending
{
t
.
Error
()
}
if
orders
[
0
]
.
GetColumn
()
!=
`user.status`
{
t
.
Error
()
}
if
orders
[
1
]
.
GetColumn
()
!=
`status`
{
t
.
Error
()
}
if
orders
[
1
]
.
GetSort
()
!=
Ascending
{
t
.
Error
()
}
if
orders
[
2
]
.
GetColumn
()
!=
`user.status`
{
t
.
Error
()
}
}
func
TestOrder_GetColumn
(
t
*
testing
.
T
)
{
o
:=
Clause
(
Column
(
`user__id`
),
)
if
o
.
GetColumn
()
!=
`user.id`
{
t
.
Error
()
}
}
func
TestOrder_GetSort
(
t
*
testing
.
T
)
{
o
:=
Clause
(
SortDescending
(),
)
if
o
.
GetSort
()
!=
Descending
{
t
.
Error
()
}
}
func
TestOrder_IsRaw
(
t
*
testing
.
T
)
{
o1
:=
Clause
()
if
o1
.
IsRaw
()
{
t
.
Error
()
}
o2
:=
Clause
(
Raw
(),
)
if
!
o2
.
IsRaw
()
{
t
.
Error
()
}
}
client/orm/db_tables.go
浏览文件 @
59b92c03
...
...
@@ -16,6 +16,8 @@ package orm
import
(
"fmt"
"github.com/astaxie/beego/client/orm/clauses"
"github.com/astaxie/beego/client/orm/clauses/order_clause"
"strings"
"time"
)
...
...
@@ -421,7 +423,7 @@ func (t *dbTables) getGroupSQL(groups []string) (groupSQL string) {
}
// generate order sql.
func
(
t
*
dbTables
)
getOrderSQL
(
orders
[]
string
)
(
orderSQL
string
)
{
func
(
t
*
dbTables
)
getOrderSQL
(
orders
[]
*
order_clause
.
Order
)
(
orderSQL
string
)
{
if
len
(
orders
)
==
0
{
return
}
...
...
@@ -430,19 +432,25 @@ func (t *dbTables) getOrderSQL(orders []string) (orderSQL string) {
orderSqls
:=
make
([]
string
,
0
,
len
(
orders
))
for
_
,
order
:=
range
orders
{
asc
:=
"ASC"
if
order
[
0
]
==
'-'
{
asc
=
"DESC"
order
=
order
[
1
:
]
}
exprs
:=
strings
.
Split
(
order
,
ExprSep
)
column
:=
order
.
GetColumn
()
clause
:=
strings
.
Split
(
column
,
clauses
.
ExprDot
)
if
order
.
IsRaw
()
{
if
len
(
clause
)
==
2
{
orderSqls
=
append
(
orderSqls
,
fmt
.
Sprintf
(
"%s.%s%s%s %s"
,
clause
[
0
],
Q
,
clause
[
1
],
Q
,
order
.
SortString
()))
}
else
if
len
(
clause
)
==
1
{
orderSqls
=
append
(
orderSqls
,
fmt
.
Sprintf
(
"%s%s%s %s"
,
Q
,
clause
[
0
],
Q
,
order
.
SortString
()))
}
else
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
clause
,
ExprSep
)))
}
}
else
{
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
clause
)
if
!
suc
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
clause
,
ExprSep
)))
}
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
exprs
)
if
!
suc
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
exprs
,
ExprSep
)))
orderSqls
=
append
(
orderSqls
,
fmt
.
Sprintf
(
"%s.%s%s%s %s"
,
index
,
Q
,
fi
.
column
,
Q
,
order
.
SortString
()))
}
orderSqls
=
append
(
orderSqls
,
fmt
.
Sprintf
(
"%s.%s%s%s %s"
,
index
,
Q
,
fi
.
column
,
Q
,
asc
))
}
orderSQL
=
fmt
.
Sprintf
(
"ORDER BY %s "
,
strings
.
Join
(
orderSqls
,
", "
))
...
...
client/orm/orm.go
浏览文件 @
59b92c03
...
...
@@ -58,6 +58,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/astaxie/beego/client/orm/clauses/order_clause"
"os"
"reflect"
"time"
...
...
@@ -351,7 +352,7 @@ func (o *ormBase) LoadRelatedWithCtx(ctx context.Context, md interface{}, name s
qs
.
relDepth
=
relDepth
if
len
(
order
)
>
0
{
qs
.
orders
=
[]
string
{
order
}
qs
.
orders
=
order_clause
.
ParseOrder
(
order
)
}
find
:=
ind
.
FieldByIndex
(
fi
.
fieldIndex
)
...
...
client/orm/orm_conds.go
浏览文件 @
59b92c03
...
...
@@ -16,12 +16,13 @@ package orm
import
(
"fmt"
"github.com/astaxie/beego/client/orm/clauses"
"strings"
)
// ExprSep define the expression separation
const
(
ExprSep
=
"__"
ExprSep
=
clauses
.
ExprSep
)
type
condValue
struct
{
...
...
client/orm/orm_queryset.go
浏览文件 @
59b92c03
...
...
@@ -17,8 +17,8 @@ package orm
import
(
"context"
"fmt"
"github.com/astaxie/beego/client/orm/hints"
"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
[]
string
orders
[]
*
order_clause
.
Order
distinct
bool
forUpdate
bool
useIndex
int
...
...
@@ -139,8 +139,20 @@ func (o querySet) GroupBy(exprs ...string) QuerySeter {
// add ORDER expression.
// "column" means ASC, "-column" means DESC.
func
(
o
querySet
)
OrderBy
(
exprs
...
string
)
QuerySeter
{
o
.
orders
=
exprs
func
(
o
querySet
)
OrderBy
(
expressions
...
string
)
QuerySeter
{
if
len
(
expressions
)
<=
0
{
return
&
o
}
o
.
orders
=
order_clause
.
ParseOrder
(
expressions
...
)
return
&
o
}
// add ORDER expression.
func
(
o
querySet
)
OrderClauses
(
orders
...*
order_clause
.
Order
)
QuerySeter
{
if
len
(
orders
)
<=
0
{
return
&
o
}
o
.
orders
=
orders
return
&
o
}
...
...
client/orm/orm_test.go
浏览文件 @
59b92c03
...
...
@@ -21,6 +21,7 @@ import (
"context"
"database/sql"
"fmt"
"github.com/astaxie/beego/client/orm/clauses/order_clause"
"io/ioutil"
"math"
"os"
...
...
@@ -1077,6 +1078,26 @@ func TestOrderBy(t *testing.T) {
num
,
err
=
qs
.
OrderBy
(
"-profile__age"
)
.
Filter
(
"user_name"
,
"astaxie"
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
num
,
err
=
qs
.
OrderClauses
(
order_clause
.
Clause
(
order_clause
.
Column
(
`profile__age`
),
order_clause
.
SortDescending
(),
),
)
.
Filter
(
"user_name"
,
"astaxie"
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
if
IsMysql
{
num
,
err
=
qs
.
OrderClauses
(
order_clause
.
Clause
(
order_clause
.
Column
(
`rand()`
),
order_clause
.
Raw
(),
),
)
.
Filter
(
"user_name"
,
"astaxie"
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
}
}
func
TestAll
(
t
*
testing
.
T
)
{
...
...
@@ -1163,6 +1184,19 @@ func TestValues(t *testing.T) {
throwFail
(
t
,
AssertIs
(
maps
[
2
][
"Profile"
],
nil
))
}
num
,
err
=
qs
.
OrderClauses
(
order_clause
.
Clause
(
order_clause
.
Column
(
"Id"
),
order_clause
.
SortAscending
(),
),
)
.
Values
(
&
maps
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
3
))
if
num
==
3
{
throwFail
(
t
,
AssertIs
(
maps
[
0
][
"UserName"
],
"slene"
))
throwFail
(
t
,
AssertIs
(
maps
[
2
][
"Profile"
],
nil
))
}
num
,
err
=
qs
.
OrderBy
(
"Id"
)
.
Values
(
&
maps
,
"UserName"
,
"Profile__Age"
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
3
))
...
...
client/orm/types.go
浏览文件 @
59b92c03
...
...
@@ -17,6 +17,7 @@ package orm
import
(
"context"
"database/sql"
"github.com/astaxie/beego/client/orm/clauses/order_clause"
"reflect"
"time"
...
...
@@ -289,6 +290,28 @@ type QuerySeter interface {
// for example:
// qs.OrderBy("-status")
OrderBy
(
exprs
...
string
)
QuerySeter
// add ORDER expression by order clauses
// for example:
// OrderClauses(
// order_clause.Clause(
// order.Column("Id"),
// order.SortAscending(),
// ),
// order_clause.Clause(
// order.Column("status"),
// order.SortDescending(),
// ),
// )
// OrderClauses(order_clause.Clause(
// order_clause.Column(`user__status`),
// order_clause.SortDescending(),//default None
// ))
// 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_clause
.
Order
)
QuerySeter
// add FORCE INDEX expression.
// for example:
// qs.ForceIndex(`idx_name1`,`idx_name2`)
...
...
task/task.go
浏览文件 @
59b92c03
...
...
@@ -452,9 +452,11 @@ func (m *taskManager) StartTask() {
func
(
m
*
taskManager
)
run
()
{
now
:=
time
.
Now
()
.
Local
()
m
.
taskLock
.
Lock
()
for
_
,
t
:=
range
m
.
adminTaskList
{
t
.
SetNext
(
nil
,
now
)
}
m
.
taskLock
.
Unlock
()
for
{
// we only use RLock here because NewMapSorter copy the reference, do not change any thing
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录