Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ceb4aa9e
authored
2013-11-24 14:26:32 +0800
by
bronze1man
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[orm] QueryTable with nil ptr struct
1 parent
a0dff914
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
orm/orm.go
orm/orm_test.go
orm/utils.go
orm/orm.go
View file @
ceb4aa9
...
...
@@ -274,9 +274,7 @@ func (o *orm) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
qs
=
newQuerySet
(
o
,
mi
)
}
}
else
{
val
:=
reflect
.
ValueOf
(
ptrStructOrTableName
)
ind
:=
reflect
.
Indirect
(
val
)
name
=
getFullName
(
ind
.
Type
())
name
=
getFullName
(
indirectType
(
reflect
.
TypeOf
(
ptrStructOrTableName
)))
if
mi
,
ok
:=
modelCache
.
getByFN
(
name
);
ok
{
qs
=
newQuerySet
(
o
,
mi
)
}
...
...
orm/orm_test.go
View file @
ceb4aa9
...
...
@@ -473,6 +473,7 @@ The program—and web server—godoc processes Go source files to extract docume
func
TestExpr
(
t
*
testing
.
T
)
{
user
:=
&
User
{}
qs
:=
dORM
.
QueryTable
(
user
)
qs
=
dORM
.
QueryTable
((
*
User
)(
nil
))
qs
=
dORM
.
QueryTable
(
"User"
)
qs
=
dORM
.
QueryTable
(
"user"
)
num
,
err
:=
qs
.
Filter
(
"UserName"
,
"slene"
)
.
Filter
(
"user_name"
,
"slene"
)
.
Filter
(
"profile__Age"
,
28
)
.
Count
()
...
...
orm/utils.go
View file @
ceb4aa9
...
...
@@ -231,3 +231,13 @@ func timeParse(dateString, format string) (time.Time, error) {
func
timeFormat
(
t
time
.
Time
,
format
string
)
string
{
return
t
.
Format
(
format
)
}
func
indirectType
(
v
reflect
.
Type
)
reflect
.
Type
{
switch
v
.
Kind
()
{
case
reflect
.
Ptr
:
return
indirectType
(
v
.
Elem
())
default
:
return
v
}
return
v
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment