Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
94b5bd8e
Commit
94b5bd8e
authored
1 year ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
Изменить сигнатура функции ConvertToMongo для работы с массивом строк
parent
2d55e02b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
perxis-proto
+1
-1
1 addition, 1 deletion
perxis-proto
pkg/expr/mongo.go
+10
-3
10 additions, 3 deletions
pkg/expr/mongo.go
pkg/expr/mongo_test.go
+59
-53
59 additions, 53 deletions
pkg/expr/mongo_test.go
with
70 additions
and
57 deletions
perxis-proto
@
78fe6a1e
Compare
63410745
...
78fe6a1e
Subproject commit
63410745d6008eaa9d9b00626b5f5b6891ac9189
Subproject commit
78fe6a1ea7e2fe588e4107bf14ac85293b201163
This diff is collapsed.
Click to expand it.
pkg/expr/mongo.go
+
10
−
3
View file @
94b5bd8e
...
@@ -20,15 +20,22 @@ var geoTypes = map[string]string{
...
@@ -20,15 +20,22 @@ var geoTypes = map[string]string{
"polygon"
:
"$polygon"
,
"polygon"
:
"$polygon"
,
}
}
func
ConvertToMongo
(
ctx
context
.
Context
,
exp
string
,
env
map
[
string
]
interface
{},
identifierRenameFn
func
(
string
)
string
,
ops
...
expr
.
Option
)
(
b
bson
.
M
,
err
error
)
{
type
MongoExprConfig
struct
{
if
exp
==
""
{
Env
map
[
string
]
any
IdentifierRenameFn
func
(
s
string
)
string
Ops
[]
expr
.
Option
}
func
ConvertToMongo
(
ctx
context
.
Context
,
config
*
MongoExprConfig
,
exprs
...
string
)
(
b
bson
.
M
,
err
error
)
{
if
len
(
exprs
)
==
0
{
return
bson
.
M
{},
nil
return
bson
.
M
{},
nil
}
}
exp
:=
"("
+
strings
.
Join
(
exprs
,
") && ("
)
+
")"
tree
,
err
:=
parser
.
Parse
(
exp
)
tree
,
err
:=
parser
.
Parse
(
exp
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
convertToMongo
(
ctx
,
tree
,
env
,
i
dentifierRenameFn
,
o
ps
...
)
return
convertToMongo
(
ctx
,
tree
,
config
.
Env
,
config
.
I
dentifierRenameFn
,
config
.
O
ps
...
)
}
}
func
convertToMongo
(
ctx
context
.
Context
,
tree
*
parser
.
Tree
,
env
map
[
string
]
interface
{},
identifierRenameFn
func
(
string
)
string
,
ops
...
expr
.
Option
)
(
b
bson
.
M
,
err
error
)
{
func
convertToMongo
(
ctx
context
.
Context
,
tree
*
parser
.
Tree
,
env
map
[
string
]
interface
{},
identifierRenameFn
func
(
string
)
string
,
ops
...
expr
.
Option
)
(
b
bson
.
M
,
err
error
)
{
...
...
This diff is collapsed.
Click to expand it.
pkg/expr/mongo_test.go
+
59
−
53
View file @
94b5bd8e
...
@@ -22,65 +22,69 @@ func TestConvertToMongo(t *testing.T) {
...
@@ -22,65 +22,69 @@ func TestConvertToMongo(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
eval
string
eval
[]
string
env
map
[
string
]
interface
{}
env
map
[
string
]
interface
{}
wantB
bson
.
M
wantB
bson
.
M
wantErr
bool
wantErr
bool
}{
}{
{
"equal"
,
"s == 3"
,
nil
,
bson
.
M
{
"s"
:
3
},
false
},
{
"equal"
,
[]
string
{
"s == 3"
},
nil
,
bson
.
M
{
"s"
:
3
},
false
},
{
"in array"
,
"s in [1,2,3]"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"equal (with []string)"
,
[]
string
{
"object.space_id == 'sp'"
,
"object.organization_id == 'org'"
},
nil
,
bson
.
M
{
"$and"
:
bson
.
A
{
bson
.
M
{
"object.space_id"
:
"sp"
},
bson
.
M
{
"object.organization_id"
:
"org"
}}},
false
},
{
"not in array"
,
"s not in [1,2,3]"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$nin"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"equal (with nil []string)"
,
nil
,
nil
,
bson
.
M
{},
false
},
{
"exists#1"
,
"exists(s)"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"in array"
,
[]
string
{
"s in [1,2,3]"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"exists#2"
,
"exists(s, s)"
,
nil
,
nil
,
true
},
{
"not in array"
,
[]
string
{
"s not in [1,2,3]"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$nin"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"len#1"
,
"len(s)"
,
nil
,
nil
,
true
},
{
"exists#1"
,
[]
string
{
"exists(s)"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len#2"
,
"len(s) <> 1"
,
nil
,
nil
,
true
},
{
"exists#2"
,
[]
string
{
"exists(s, s)"
},
nil
,
nil
,
true
},
{
"len#3"
,
"len(s) == -1"
,
nil
,
nil
,
true
},
{
"len#1"
,
[]
string
{
"len(s)"
},
nil
,
nil
,
true
},
{
"len#4"
,
"len(s, s) == -1"
,
nil
,
nil
,
true
},
{
"len#2"
,
[]
string
{
"len(s) <> 1"
},
nil
,
nil
,
true
},
{
"len#5"
,
"len(s) == s"
,
nil
,
nil
,
true
},
{
"len#3"
,
[]
string
{
"len(s) == -1"
},
nil
,
nil
,
true
},
{
"len eq"
,
"len(s) == 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$size"
:
1
}},
false
},
{
"len#4"
,
[]
string
{
"len(s, s) == -1"
},
nil
,
nil
,
true
},
{
"len eq zero"
,
"len(s) == 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len#5"
,
[]
string
{
"len(s) == s"
},
nil
,
nil
,
true
},
{
"len ne"
,
"len(s) != 1"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
1
},
"$type"
:
"array"
}},
false
},
{
"len eq"
,
[]
string
{
"len(s) == 1"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$size"
:
1
}},
false
},
{
"len ne zero"
,
"len(s) != 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$ne"
:
bson
.
A
{},
"$type"
:
"array"
}},
false
},
{
"len eq zero"
,
[]
string
{
"len(s) == 0"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len gt"
,
"len(s) > 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len ne"
,
[]
string
{
"len(s) != 1"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$not"
:
bson
.
M
{
"$size"
:
1
},
"$type"
:
"array"
}},
false
},
{
"len gt zero"
,
"len(s) > 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}},
false
},
{
"len ne zero"
,
[]
string
{
"len(s) != 0"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$ne"
:
bson
.
A
{},
"$type"
:
"array"
}},
false
},
{
"len gte"
,
"len(s) >= 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gt"
,
[]
string
{
"len(s) > 1"
},
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len gte zero"
,
"len(s) >= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
false
},
{
"len gt zero"
,
[]
string
{
"len(s) > 0"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
,
"$ne"
:
bson
.
A
{}}},
false
},
{
"len lt"
,
"len(s) < 1"
,
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
false
},
"s"
:
bson
.
M
{
"$type"
:
"array"
}},
false
},
{
"len gte"
,
[]
string
{
"len(s) >= 1"
},
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
true
}},
false
},
{
"len lt zero"
,
"len(s) < 0"
,
nil
,
nil
,
true
},
{
"len gte zero"
,
[]
string
{
"len(s) >= 0"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$exists"
:
true
,
"$type"
:
"array"
}},
false
},
{
"len lte"
,
"len(s) <= 1"
,
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
false
},
"s"
:
bson
.
M
{
"$type"
:
"array"
}},
false
},
{
"len lt"
,
[]
string
{
"len(s) < 1"
},
nil
,
bson
.
M
{
"s.0"
:
bson
.
M
{
"$exists"
:
false
},
"s"
:
bson
.
M
{
"$type"
:
"array"
}},
false
},
{
"len lte zero"
,
"len(s) <= 0"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"len lt zero"
,
[]
string
{
"len(s) < 0"
},
nil
,
nil
,
true
},
{
"field#1"
,
"s.test > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"len lte"
,
[]
string
{
"len(s) <= 1"
},
nil
,
bson
.
M
{
"s.1"
:
bson
.
M
{
"$exists"
:
false
},
"s"
:
bson
.
M
{
"$type"
:
"array"
}},
false
},
{
"field#2"
,
"s['test'] > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"len lte zero"
,
[]
string
{
"len(s) <= 0"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$eq"
:
bson
.
A
{}}},
false
},
{
"field#3"
,
"s[test] > 3"
,
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"field#1"
,
[]
string
{
"s.test > 3"
},
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"contains"
,
"s contains 'some'"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"some"
}},
false
},
{
"field#2"
,
[]
string
{
"s['test'] > 3"
},
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"contains with . + () $ {} ^"
,
"value contains 'something with . + () $ {} ^'"
,
nil
,
bson
.
M
{
"value"
:
bson
.
M
{
"$regex"
:
"something with
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^"
}},
false
},
{
"field#3"
,
[]
string
{
"s[test] > 3"
},
nil
,
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}},
false
},
{
"startsWith"
,
"s startsWith 'some'"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^some.*"
}},
false
},
{
"contains"
,
[]
string
{
"s contains 'some'"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"some"
}},
false
},
{
"startsWith . + () $ {} ^"
,
"s startsWith '. + () $ {} ^'"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^.*"
}},
false
},
{
"contains with . + () $ {} ^"
,
[]
string
{
"value contains 'something with . + () $ {} ^'"
},
nil
,
bson
.
M
{
"value"
:
bson
.
M
{
"$regex"
:
"something with
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^"
}},
false
},
{
"endsWith"
,
"s endsWith 'some'"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*some$"
}},
false
},
{
"startsWith"
,
[]
string
{
"s startsWith 'some'"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^some.*"
}},
false
},
{
"endsWith . + () $ {} ^"
,
"s endsWith '. + () $ {} ^'"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^$"
}},
false
},
{
"startsWith . + () $ {} ^"
,
[]
string
{
"s startsWith '. + () $ {} ^'"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^.*"
}},
false
},
{
"icontains"
,
"icontains(s, 'some')"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"some"
,
"$options"
:
"i"
}},
false
},
{
"endsWith"
,
[]
string
{
"s endsWith 'some'"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*some$"
}},
false
},
{
"icontains with . + () $ {} ^"
,
"icontains (value, 'something with . + () $ {} ^')"
,
nil
,
bson
.
M
{
"value"
:
bson
.
M
{
"$regex"
:
"something with
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^"
,
"$options"
:
"i"
}},
false
},
{
"endsWith . + () $ {} ^"
,
[]
string
{
"s endsWith '. + () $ {} ^'"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^$"
}},
false
},
{
"istartsWith"
,
"istartsWith(s, 'Some')"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^Some.*"
,
"$options"
:
"i"
}},
false
},
{
"icontains"
,
[]
string
{
"icontains(s, 'some')"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"some"
,
"$options"
:
"i"
}},
false
},
{
"istartsWith . + () $ {} ^ . + () $ {} ^"
,
"istartsWith(s, '. + () $ {} ^')"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^.*"
,
"$options"
:
"i"
}},
false
},
{
"icontains with . + () $ {} ^"
,
[]
string
{
"icontains (value, 'something with . + () $ {} ^')"
},
nil
,
bson
.
M
{
"value"
:
bson
.
M
{
"$regex"
:
"something with
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^"
,
"$options"
:
"i"
}},
false
},
{
"iendsWith"
,
"iendsWith(s, 'some')"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*some$"
,
"$options"
:
"i"
}},
false
},
{
"istartsWith"
,
[]
string
{
"istartsWith(s, 'Some')"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^Some.*"
,
"$options"
:
"i"
}},
false
},
{
"iendsWith . + () $ {} ^"
,
"iendsWith(s,'. + () $ {} ^')"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^$"
,
"$options"
:
"i"
}},
false
},
{
"istartsWith . + () $ {} ^ . + () $ {} ^"
,
[]
string
{
"istartsWith(s, '. + () $ {} ^')"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
"^
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^.*"
,
"$options"
:
"i"
}},
false
},
{
"or"
,
"s==2 || s > 10"
,
nil
,
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"s"
:
2
},
bson
.
M
{
"s"
:
bson
.
M
{
"$gt"
:
10
}}}},
false
},
{
"iendsWith"
,
[]
string
{
"iendsWith(s, 'some')"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*some$"
,
"$options"
:
"i"
}},
false
},
{
"not#1"
,
"not icontains(s, 'some')"
,
nil
,
bson
.
M
{
"$nor"
:
bson
.
A
{
bson
.
M
{
"s"
:
bson
.
M
{
"$options"
:
"i"
,
"$regex"
:
"some"
}}}},
false
},
{
"iendsWith . + () $ {} ^"
,
[]
string
{
"iendsWith(s,'. + () $ {} ^')"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$regex"
:
".*
\\
.
\\
+
\\
(
\\
)
\\
$
\\
{
\\
}
\\
^$"
,
"$options"
:
"i"
}},
false
},
{
"not#2"
,
"not (s.test > 3)"
,
nil
,
bson
.
M
{
"$nor"
:
bson
.
A
{
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}}}},
false
},
{
"or"
,
[]
string
{
"s==2 || s > 10"
},
nil
,
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"s"
:
2
},
bson
.
M
{
"s"
:
bson
.
M
{
"$gt"
:
10
}}}},
false
},
{
"search"
,
"search('some') || s > 10"
,
nil
,
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"$text"
:
bson
.
M
{
"$search"
:
"some"
}},
bson
.
M
{
"s"
:
bson
.
M
{
"$gt"
:
10
}}}},
false
},
{
"not#1"
,
[]
string
{
"not icontains(s, 'some')"
},
nil
,
bson
.
M
{
"$nor"
:
bson
.
A
{
bson
.
M
{
"s"
:
bson
.
M
{
"$options"
:
"i"
,
"$regex"
:
"some"
}}}},
false
},
{
"vars:or"
,
"s== a + 2 || s > a + 10"
,
map
[
string
]
interface
{}{
"a"
:
100
},
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"s"
:
102
},
bson
.
M
{
"s"
:
bson
.
M
{
"$gt"
:
110
}}}},
false
},
{
"not#2"
,
[]
string
{
"not (s.test > 3)"
},
nil
,
bson
.
M
{
"$nor"
:
bson
.
A
{
bson
.
M
{
"s.test"
:
bson
.
M
{
"$gt"
:
3
}}}},
false
},
{
"near"
,
"near(a, [55.5, 37.5], 1000)"
,
map
[
string
]
interface
{}{
"a"
:
[]
interface
{}{
55
,
37
}},
bson
.
M
{
"a.geometry"
:
bson
.
M
{
"$near"
:
bson
.
D
{{
Key
:
"$geometry"
,
Value
:
map
[
string
]
interface
{}{
"coordinates"
:
[]
interface
{}{
55.5
,
37.5
},
"type"
:
"Point"
}},
{
Key
:
"$maxDistance"
,
Value
:
1000
}}}},
false
},
{
"search"
,
[]
string
{
"search('some') || s > 10"
},
nil
,
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"$text"
:
bson
.
M
{
"$search"
:
"some"
}},
bson
.
M
{
"s"
:
bson
.
M
{
"$gt"
:
10
}}}},
false
},
{
"within"
,
"within(a, 'box', [[54.54, 36.36], [55.55, 37.37]])"
,
map
[
string
]
interface
{}{
"a"
:
[]
interface
{}{
55
,
37
}},
bson
.
M
{
"a.geometry"
:
bson
.
M
{
"$geoWithin"
:
bson
.
M
{
"$box"
:
[]
interface
{}{[]
interface
{}{
54.54
,
36.36
},
[]
interface
{}{
55.55
,
37.37
}}}}},
false
},
{
"vars:or"
,
[]
string
{
"s== a + 2 || s > a + 10"
},
map
[
string
]
interface
{}{
"a"
:
100
},
bson
.
M
{
"$or"
:
bson
.
A
{
bson
.
M
{
"s"
:
102
},
bson
.
M
{
"s"
:
bson
.
M
{
"$gt"
:
110
}}}},
false
},
{
"time"
,
"d > Time.Date('2021-08-31')"
,
nil
,
bson
.
M
{
"d"
:
bson
.
M
{
"$gt"
:
dt
}},
false
},
{
"near"
,
[]
string
{
"near(a, [55.5, 37.5], 1000)"
},
map
[
string
]
interface
{}{
"a"
:
[]
interface
{}{
55
,
37
}},
bson
.
M
{
"a.geometry"
:
bson
.
M
{
"$near"
:
bson
.
D
{{
Key
:
"$geometry"
,
Value
:
map
[
string
]
interface
{}{
"coordinates"
:
[]
interface
{}{
55.5
,
37.5
},
"type"
:
"Point"
}},
{
Key
:
"$maxDistance"
,
Value
:
1000
}}}},
false
},
{
"time"
,
fmt
.
Sprintf
(
"d > Time.Time('%s')"
,
now
.
Format
(
time
.
RFC3339
)),
nil
,
bson
.
M
{
"d"
:
bson
.
M
{
"$gt"
:
tm
}},
false
},
{
"within"
,
[]
string
{
"within(a, 'box', [[54.54, 36.36], [55.55, 37.37]])"
},
map
[
string
]
interface
{}{
"a"
:
[]
interface
{}{
55
,
37
}},
bson
.
M
{
"a.geometry"
:
bson
.
M
{
"$geoWithin"
:
bson
.
M
{
"$box"
:
[]
interface
{}{[]
interface
{}{
54.54
,
36.36
},
[]
interface
{}{
55.55
,
37.37
}}}}},
false
},
{
"in"
,
"In(s, [1,2,3])"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"time"
,
[]
string
{
"d > Time.Date('2021-08-31')"
},
nil
,
bson
.
M
{
"d"
:
bson
.
M
{
"$gt"
:
dt
}},
false
},
{
"in"
,
"In(s, 1)"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
}}},
false
},
{
"time"
,
[]
string
{
fmt
.
Sprintf
(
"d > Time.Time('%s')"
,
now
.
Format
(
time
.
RFC3339
))},
nil
,
bson
.
M
{
"d"
:
bson
.
M
{
"$gt"
:
tm
}},
false
},
{
"text search or id"
,
"id"
,
nil
,
nil
,
true
},
{
"in"
,
[]
string
{
"In(s, [1,2,3])"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"struct env"
,
"db_item.id == env_item.id"
,
map
[
string
]
interface
{}{
"env_item"
:
&
testEnvStruct
{
ID
:
"id1"
}},
bson
.
M
{
"db_item.id"
:
"id1"
},
false
},
{
"in"
,
[]
string
{
"In(s, 1)"
},
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
}}},
false
},
{
"text search or id"
,
[]
string
{
"id"
},
nil
,
nil
,
true
},
{
"struct env"
,
[]
string
{
"db_item.id == env_item.id"
},
map
[
string
]
interface
{}{
"env_item"
:
&
testEnvStruct
{
ID
:
"id1"
}},
bson
.
M
{
"db_item.id"
:
"id1"
},
false
},
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
gotB
,
err
:=
ConvertToMongo
(
ctx
,
tt
.
eval
,
tt
.
env
,
nil
)
config
:=
&
MongoExprConfig
{
Env
:
tt
.
env
}
gotB
,
err
:=
ConvertToMongo
(
ctx
,
config
,
tt
.
eval
...
)
if
tt
.
wantErr
{
if
tt
.
wantErr
{
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
return
return
...
@@ -102,8 +106,10 @@ func BenchmarkConvertToMongo(b *testing.B) {
...
@@ -102,8 +106,10 @@ func BenchmarkConvertToMongo(b *testing.B) {
exp
:=
InStringArray
(
"id"
,
ids
)
exp
:=
InStringArray
(
"id"
,
ids
)
//fmt.Println(len(exp))
//fmt.Println(len(exp))
config
:=
&
MongoExprConfig
{
Ops
:
[]
expr
.
Option
{
expr
.
Patch
(
&
testVisitor
{})}}
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
_
,
_
=
ConvertToMongo
(
ctx
,
exp
,
nil
,
nil
,
expr
.
Patch
(
&
testVisitor
{})
)
_
,
_
=
ConvertToMongo
(
ctx
,
config
,
exp
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment