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
cacdb322
authored
2014-03-10 20:18:57 +0800
by
slene
Committed by
asta.xie
2014-03-12 15:56:05 +0800
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
orm add operator `between` #518
1 parent
d0949b64
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
orm/db.go
orm/orm_test.go
orm/db.go
View file @
cacdb32
...
...
@@ -35,7 +35,7 @@ var (
"istartswith"
:
true
,
"iendswith"
:
true
,
"in"
:
true
,
// "range":
true,
"between"
:
true
,
// "year": true,
// "month": true,
// "day": true,
...
...
@@ -916,13 +916,19 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri
}
arg
:=
params
[
0
]
if
operator
==
"in"
{
switch
operator
{
case
"in"
:
marks
:=
make
([]
string
,
len
(
params
))
for
i
,
_
:=
range
marks
{
marks
[
i
]
=
"?"
}
sql
=
fmt
.
Sprintf
(
"IN (%s)"
,
strings
.
Join
(
marks
,
", "
))
}
else
{
case
"between"
:
if
len
(
params
)
!=
2
{
panic
(
fmt
.
Errorf
(
"operator `%s` need 2 args not %d"
,
operator
,
len
(
params
)))
}
sql
=
"BETWEEN ? AND ?"
default
:
if
len
(
params
)
>
1
{
panic
(
fmt
.
Errorf
(
"operator `%s` need 1 args not %d"
,
operator
,
len
(
params
)))
}
...
...
orm/orm_test.go
View file @
cacdb32
...
...
@@ -653,6 +653,14 @@ func TestOperators(t *testing.T) {
num
,
err
=
qs
.
Filter
(
"status__in"
,
[]
*
int
{
&
n1
},
&
n2
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
num
,
err
=
qs
.
Filter
(
"id__between"
,
2
,
3
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
num
,
err
=
qs
.
Filter
(
"id__between"
,
[]
int
{
2
,
3
})
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
}
func
TestSetCond
(
t
*
testing
.
T
)
{
...
...
@@ -1611,7 +1619,6 @@ func TestDelete(t *testing.T) {
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
4
))
fmt
.
Println
(
"..."
)
qs
=
dORM
.
QueryTable
(
"comment"
)
num
,
err
=
qs
.
Filter
(
"Post__User"
,
3
)
.
Delete
()
throwFail
(
t
,
err
)
...
...
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