Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
433e8f2c
Commit
433e8f2c
authored
Feb 14, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Add GroupBy to QuerySeter"
parent
22ba7fdc
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
3 additions
and
59 deletions
+3
-59
db.go
orm/db.go
+3
-6
db_tables.go
orm/db_tables.go
+0
-24
orm_queryset.go
orm/orm_queryset.go
+0
-7
orm_test.go
orm/orm_test.go
+0
-21
types.go
orm/types.go
+0
-1
No files found.
orm/db.go
View file @
433e8f2c
...
@@ -800,7 +800,6 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
...
@@ -800,7 +800,6 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
tables
.
parseRelated
(
qs
.
related
,
qs
.
relDepth
)
tables
.
parseRelated
(
qs
.
related
,
qs
.
relDepth
)
where
,
args
:=
tables
.
getCondSql
(
cond
,
false
,
tz
)
where
,
args
:=
tables
.
getCondSql
(
cond
,
false
,
tz
)
groupBy
:=
tables
.
getGroupSql
(
qs
.
groups
)
orderBy
:=
tables
.
getOrderSql
(
qs
.
orders
)
orderBy
:=
tables
.
getOrderSql
(
qs
.
orders
)
limit
:=
tables
.
getLimitSql
(
mi
,
offset
,
rlimit
)
limit
:=
tables
.
getLimitSql
(
mi
,
offset
,
rlimit
)
join
:=
tables
.
getJoinSql
()
join
:=
tables
.
getJoinSql
()
...
@@ -813,7 +812,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
...
@@ -813,7 +812,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
}
}
}
}
query
:=
fmt
.
Sprintf
(
"SELECT %s FROM %s%s%s T0 %s%s%s%s
%s"
,
sels
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
groupBy
,
orderBy
,
limit
)
query
:=
fmt
.
Sprintf
(
"SELECT %s FROM %s%s%s T0 %s%s%s%s
"
,
sels
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
orderBy
,
limit
)
d
.
ins
.
ReplaceMarks
(
&
query
)
d
.
ins
.
ReplaceMarks
(
&
query
)
...
@@ -937,13 +936,12 @@ func (d *dbBase) Count(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition
...
@@ -937,13 +936,12 @@ func (d *dbBase) Count(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition
tables
.
parseRelated
(
qs
.
related
,
qs
.
relDepth
)
tables
.
parseRelated
(
qs
.
related
,
qs
.
relDepth
)
where
,
args
:=
tables
.
getCondSql
(
cond
,
false
,
tz
)
where
,
args
:=
tables
.
getCondSql
(
cond
,
false
,
tz
)
groupBy
:=
tables
.
getGroupSql
(
qs
.
groups
)
tables
.
getOrderSql
(
qs
.
orders
)
tables
.
getOrderSql
(
qs
.
orders
)
join
:=
tables
.
getJoinSql
()
join
:=
tables
.
getJoinSql
()
Q
:=
d
.
ins
.
TableQuote
()
Q
:=
d
.
ins
.
TableQuote
()
query
:=
fmt
.
Sprintf
(
"SELECT COUNT(*) FROM %s%s%s T0 %s%s
%s"
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
groupBy
)
query
:=
fmt
.
Sprintf
(
"SELECT COUNT(*) FROM %s%s%s T0 %s%s
"
,
Q
,
mi
.
table
,
Q
,
join
,
where
)
d
.
ins
.
ReplaceMarks
(
&
query
)
d
.
ins
.
ReplaceMarks
(
&
query
)
...
@@ -1444,14 +1442,13 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
...
@@ -1444,14 +1442,13 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
}
}
where
,
args
:=
tables
.
getCondSql
(
cond
,
false
,
tz
)
where
,
args
:=
tables
.
getCondSql
(
cond
,
false
,
tz
)
groupBy
:=
tables
.
getGroupSql
(
qs
.
groups
)
orderBy
:=
tables
.
getOrderSql
(
qs
.
orders
)
orderBy
:=
tables
.
getOrderSql
(
qs
.
orders
)
limit
:=
tables
.
getLimitSql
(
mi
,
qs
.
offset
,
qs
.
limit
)
limit
:=
tables
.
getLimitSql
(
mi
,
qs
.
offset
,
qs
.
limit
)
join
:=
tables
.
getJoinSql
()
join
:=
tables
.
getJoinSql
()
sels
:=
strings
.
Join
(
cols
,
", "
)
sels
:=
strings
.
Join
(
cols
,
", "
)
query
:=
fmt
.
Sprintf
(
"SELECT %s FROM %s%s%s T0 %s%s%s%s
%s"
,
sels
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
groupBy
,
orderBy
,
limit
)
query
:=
fmt
.
Sprintf
(
"SELECT %s FROM %s%s%s T0 %s%s%s%s
"
,
sels
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
orderBy
,
limit
)
d
.
ins
.
ReplaceMarks
(
&
query
)
d
.
ins
.
ReplaceMarks
(
&
query
)
...
...
orm/db_tables.go
View file @
433e8f2c
...
@@ -390,30 +390,6 @@ func (t *dbTables) getCondSql(cond *Condition, sub bool, tz *time.Location) (whe
...
@@ -390,30 +390,6 @@ func (t *dbTables) getCondSql(cond *Condition, sub bool, tz *time.Location) (whe
return
return
}
}
// generate group sql.
func
(
t
*
dbTables
)
getGroupSql
(
groups
[]
string
)
(
groupSql
string
)
{
if
len
(
groups
)
==
0
{
return
}
Q
:=
t
.
base
.
TableQuote
()
groupSqls
:=
make
([]
string
,
0
,
len
(
groups
))
for
_
,
group
:=
range
groups
{
exprs
:=
strings
.
Split
(
group
,
ExprSep
)
index
,
_
,
fi
,
suc
:=
t
.
parseExprs
(
t
.
mi
,
exprs
)
if
suc
==
false
{
panic
(
fmt
.
Errorf
(
"unknown field/column name `%s`"
,
strings
.
Join
(
exprs
,
ExprSep
)))
}
groupSqls
=
append
(
groupSqls
,
fmt
.
Sprintf
(
"%s.%s%s%s"
,
index
,
Q
,
fi
.
column
,
Q
))
}
groupSql
=
fmt
.
Sprintf
(
"GROUP BY %s "
,
strings
.
Join
(
groupSqls
,
", "
))
return
}
// generate order sql.
// generate order sql.
func
(
t
*
dbTables
)
getOrderSql
(
orders
[]
string
)
(
orderSql
string
)
{
func
(
t
*
dbTables
)
getOrderSql
(
orders
[]
string
)
(
orderSql
string
)
{
if
len
(
orders
)
==
0
{
if
len
(
orders
)
==
0
{
...
...
orm/orm_queryset.go
View file @
433e8f2c
...
@@ -60,7 +60,6 @@ type querySet struct {
...
@@ -60,7 +60,6 @@ type querySet struct {
relDepth
int
relDepth
int
limit
int64
limit
int64
offset
int64
offset
int64
groups
[]
string
orders
[]
string
orders
[]
string
orm
*
orm
orm
*
orm
}
}
...
@@ -106,12 +105,6 @@ func (o querySet) Offset(offset interface{}) QuerySeter {
...
@@ -106,12 +105,6 @@ func (o querySet) Offset(offset interface{}) QuerySeter {
return
&
o
return
&
o
}
}
// add GROUP expression.
func
(
o
querySet
)
GroupBy
(
exprs
...
string
)
QuerySeter
{
o
.
groups
=
exprs
return
&
o
}
// add ORDER expression.
// add ORDER expression.
// "column" means ASC, "-column" means DESC.
// "column" means ASC, "-column" means DESC.
func
(
o
querySet
)
OrderBy
(
exprs
...
string
)
QuerySeter
{
func
(
o
querySet
)
OrderBy
(
exprs
...
string
)
QuerySeter
{
...
...
orm/orm_test.go
View file @
433e8f2c
...
@@ -845,27 +845,6 @@ func TestOffset(t *testing.T) {
...
@@ -845,27 +845,6 @@ func TestOffset(t *testing.T) {
throwFail
(
t
,
AssertIs
(
num
,
2
))
throwFail
(
t
,
AssertIs
(
num
,
2
))
}
}
func
TestGroupBy
(
t
*
testing
.
T
)
{
var
users
[]
*
User
var
maps
[]
Params
qs
:=
dORM
.
QueryTable
(
"user"
)
num
,
err
:=
qs
.
GroupBy
(
"is_staff"
)
.
Filter
(
"user_name"
,
"nobody"
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
num
,
err
=
qs
.
GroupBy
(
"is_staff"
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
num
,
err
=
qs
.
GroupBy
(
"is_staff"
)
.
Values
(
&
maps
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
num
,
err
=
qs
.
GroupBy
(
"profile__age"
)
.
Filter
(
"user_name"
,
"astaxie"
)
.
All
(
&
users
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
}
func
TestOrderBy
(
t
*
testing
.
T
)
{
func
TestOrderBy
(
t
*
testing
.
T
)
{
qs
:=
dORM
.
QueryTable
(
"user"
)
qs
:=
dORM
.
QueryTable
(
"user"
)
num
,
err
:=
qs
.
OrderBy
(
"-status"
)
.
Filter
(
"user_name"
,
"nobody"
)
.
Count
()
num
,
err
:=
qs
.
OrderBy
(
"-status"
)
.
Filter
(
"user_name"
,
"nobody"
)
.
Count
()
...
...
orm/types.go
View file @
433e8f2c
...
@@ -67,7 +67,6 @@ type QuerySeter interface {
...
@@ -67,7 +67,6 @@ type QuerySeter interface {
SetCond
(
*
Condition
)
QuerySeter
SetCond
(
*
Condition
)
QuerySeter
Limit
(
interface
{},
...
interface
{})
QuerySeter
Limit
(
interface
{},
...
interface
{})
QuerySeter
Offset
(
interface
{})
QuerySeter
Offset
(
interface
{})
QuerySeter
GroupBy
(
...
string
)
QuerySeter
OrderBy
(
...
string
)
QuerySeter
OrderBy
(
...
string
)
QuerySeter
RelatedSel
(
...
interface
{})
QuerySeter
RelatedSel
(
...
interface
{})
QuerySeter
Count
()
(
int64
,
error
)
Count
()
(
int64
,
error
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment