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
167ad203
Commit
167ad203
authored
Nov 08, 2013
by
slene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orm #276
parent
558738ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
6 deletions
+37
-6
db.go
orm/db.go
+30
-4
orm_test.go
orm/orm_test.go
+7
-2
No files found.
orm/db.go
View file @
167ad203
...
...
@@ -705,7 +705,13 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
ind
.
Set
(
mind
)
}
else
{
if
cnt
==
0
{
slice
=
reflect
.
New
(
ind
.
Type
())
.
Elem
()
// you can use a empty & caped container list
// orm will not replace it
if
ind
.
Len
()
!=
0
{
// if container is not empty
// create a new one
slice
=
reflect
.
New
(
ind
.
Type
())
.
Elem
()
}
}
if
isPtr
{
...
...
@@ -718,8 +724,16 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
cnt
++
}
if
one
==
false
&&
cnt
>
0
{
ind
.
Set
(
slice
)
if
one
==
false
{
if
cnt
>
0
{
ind
.
Set
(
slice
)
}
else
{
// when a result is empty and container is nil
// to set a empty container
if
ind
.
IsNil
()
{
ind
.
Set
(
reflect
.
MakeSlice
(
ind
.
Type
(),
0
,
0
))
}
}
}
return
cnt
,
nil
...
...
@@ -1058,12 +1072,24 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
)
typ
:=
0
switch
container
.
(
type
)
{
switch
v
:=
container
.
(
type
)
{
case
*
[]
Params
:
d
:=
*
v
if
len
(
d
)
==
0
{
maps
=
d
}
typ
=
1
case
*
[]
ParamsList
:
d
:=
*
v
if
len
(
d
)
==
0
{
lists
=
d
}
typ
=
2
case
*
ParamsList
:
d
:=
*
v
if
len
(
d
)
==
0
{
list
=
d
}
typ
=
3
default
:
panic
(
fmt
.
Errorf
(
"unsupport read values type `%T`"
,
container
))
...
...
orm/orm_test.go
View file @
167ad203
...
...
@@ -696,8 +696,13 @@ func TestAll(t *testing.T) {
qs
=
dORM
.
QueryTable
(
"user"
)
num
,
err
=
qs
.
Filter
(
"user_name"
,
"nothing"
)
.
All
(
&
users
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
0
))
throwFailNow
(
t
,
err
)
throwFailNow
(
t
,
AssertIs
(
num
,
0
))
var
users3
[]
*
User
qs
=
dORM
.
QueryTable
(
"user"
)
num
,
err
=
qs
.
Filter
(
"user_name"
,
"nothing"
)
.
All
(
&
users3
)
throwFailNow
(
t
,
AssertIs
(
users3
==
nil
,
false
))
}
func
TestOne
(
t
*
testing
.
T
)
{
...
...
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