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
19d82ab6
Commit
19d82ab6
authored
Jul 22, 2015
by
Pelle Johnsen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1274: Add QuerySeter.Distinct()
parent
9775e3e3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
16 deletions
+28
-16
db.go
orm/db.go
+5
-1
orm_queryset.go
orm/orm_queryset.go
+22
-15
types.go
orm/types.go
+1
-0
No files found.
orm/db.go
View file @
19d82ab6
...
...
@@ -814,7 +814,11 @@ 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"
,
sels
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
orderBy
,
limit
)
sqlSelect
:=
"SELECT"
if
qs
.
distinct
{
sqlSelect
+=
" DISTINCT"
}
query
:=
fmt
.
Sprintf
(
"%s %s FROM %s%s%s T0 %s%s%s%s"
,
sqlSelect
,
sels
,
Q
,
mi
.
table
,
Q
,
join
,
where
,
orderBy
,
limit
)
d
.
ins
.
ReplaceMarks
(
&
query
)
...
...
orm/orm_queryset.go
View file @
19d82ab6
...
...
@@ -61,6 +61,7 @@ type querySet struct {
limit
int64
offset
int64
orders
[]
string
distinct
bool
orm
*
orm
}
...
...
@@ -112,24 +113,30 @@ func (o querySet) OrderBy(exprs ...string) QuerySeter {
return
&
o
}
// add DISTINCT to SELECT
func
(
o
querySet
)
Distinct
()
QuerySeter
{
o
.
distinct
=
true
return
&
o
}
// set relation model to query together.
// it will query relation models and assign to parent model.
func
(
o
querySet
)
RelatedSel
(
params
...
interface
{})
QuerySeter
{
if
len
(
params
)
==
0
{
o
.
relDepth
=
DefaultRelsDepth
}
else
{
for
_
,
p
:=
range
params
{
switch
val
:=
p
.
(
type
)
{
case
string
:
o
.
related
=
append
(
o
.
related
,
val
)
case
int
:
o
.
relDepth
=
val
default
:
panic
(
fmt
.
Errorf
(
"<QuerySeter.RelatedSel> wrong param kind: %v"
,
val
))
}
}
}
return
&
o
if
len
(
params
)
==
0
{
o
.
relDepth
=
DefaultRelsDepth
}
else
{
for
_
,
p
:=
range
params
{
switch
val
:=
p
.
(
type
)
{
case
string
:
o
.
related
=
append
(
o
.
related
,
val
)
case
int
:
o
.
relDepth
=
val
default
:
panic
(
fmt
.
Errorf
(
"<QuerySeter.RelatedSel> wrong param kind: %v"
,
val
))
}
}
}
return
&
o
}
// set condition to QuerySeter.
...
...
orm/types.go
View file @
19d82ab6
...
...
@@ -67,6 +67,7 @@ type QuerySeter interface {
Limit
(
interface
{},
...
interface
{})
QuerySeter
Offset
(
interface
{})
QuerySeter
OrderBy
(
...
string
)
QuerySeter
Distinct
()
QuerySeter
RelatedSel
(
...
interface
{})
QuerySeter
Count
()
(
int64
,
error
)
Exist
()
bool
...
...
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