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
34e2b26b
Commit
34e2b26b
authored
Nov 28, 2016
by
Dusan Kasan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolves #2291, introduces AndNotCond/OrNotCond to orm.Condition
parent
24015e9a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
orm_conds.go
orm/orm_conds.go
+26
-0
orm_test.go
orm/orm_test.go
+10
-0
No files found.
orm/orm_conds.go
View file @
34e2b26b
...
...
@@ -75,6 +75,19 @@ func (c *Condition) AndCond(cond *Condition) *Condition {
return
c
}
// AndNotCond combine a AND NOT condition to current condition
func
(
c
*
Condition
)
AndNotCond
(
cond
*
Condition
)
*
Condition
{
c
=
c
.
clone
()
if
c
==
cond
{
panic
(
fmt
.
Errorf
(
"<Condition.AndNotCond> cannot use self as sub cond"
))
}
if
cond
!=
nil
{
c
.
params
=
append
(
c
.
params
,
condValue
{
cond
:
cond
,
isCond
:
true
,
isNot
:
true
})
}
return
c
}
// Or add OR expression to condition
func
(
c
Condition
)
Or
(
expr
string
,
args
...
interface
{})
*
Condition
{
if
expr
==
""
||
len
(
args
)
==
0
{
...
...
@@ -105,6 +118,19 @@ func (c *Condition) OrCond(cond *Condition) *Condition {
return
c
}
// OrNotCond combine a OR NOT condition to current condition
func
(
c
*
Condition
)
OrNotCond
(
cond
*
Condition
)
*
Condition
{
c
=
c
.
clone
()
if
c
==
cond
{
panic
(
fmt
.
Errorf
(
"<Condition.OrNotCond> cannot use self as sub cond"
))
}
if
cond
!=
nil
{
c
.
params
=
append
(
c
.
params
,
condValue
{
cond
:
cond
,
isCond
:
true
,
isNot
:
true
,
isOr
:
true
})
}
return
c
}
// IsEmpty check the condition arguments are empty or not.
func
(
c
*
Condition
)
IsEmpty
()
bool
{
return
len
(
c
.
params
)
==
0
...
...
orm/orm_test.go
View file @
34e2b26b
...
...
@@ -909,6 +909,16 @@ func TestSetCond(t *testing.T) {
num
,
err
=
qs
.
SetCond
(
cond2
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
cond3
:=
cond
.
AndNotCond
(
cond
.
And
(
"status__in"
,
1
))
num
,
err
=
qs
.
SetCond
(
cond3
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
2
))
cond4
:=
cond
.
And
(
"user_name"
,
"slene"
)
.
OrNotCond
(
cond
.
And
(
"user_name"
,
"slene"
))
num
,
err
=
qs
.
SetCond
(
cond4
)
.
Count
()
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
3
))
}
func
TestLimit
(
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