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
cdfe0757
Commit
cdfe0757
authored
1 year ago
by
Pavel Antonov
Browse files
Options
Downloads
Plain Diff
Исправлен метод библиотеки expr - если выражение является строкой возвращается ошибка
Close #PRXS-1608
parents
f5ce5cef
57fdf790
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/expr/mongo.go
+4
-9
4 additions, 9 deletions
pkg/expr/mongo.go
pkg/expr/mongo_test.go
+6
-1
6 additions, 1 deletion
pkg/expr/mongo_test.go
pkg/items/service.go
+3
-2
3 additions, 2 deletions
pkg/items/service.go
with
13 additions
and
12 deletions
pkg/expr/mongo.go
+
4
−
9
View file @
cdfe0757
...
@@ -57,16 +57,11 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter
...
@@ -57,16 +57,11 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter
}
}
c
:=
&
compiler
{
tree
:
tree
,
env
:
env
,
config
:
config
,
identifierRenameFn
:
identifierRenameFn
}
c
:=
&
compiler
{
tree
:
tree
,
env
:
env
,
config
:
config
,
identifierRenameFn
:
identifierRenameFn
}
v
:=
c
.
compile
(
tree
.
Node
)
v
,
ok
:=
c
.
compile
(
tree
.
Node
)
.
(
bson
.
M
)
switch
e
:=
v
.
(
type
)
{
if
!
ok
||
v
==
nil
{
case
bson
.
M
:
return
nil
,
fmt
.
Errorf
(
"invalid expression"
)
b
=
e
case
string
:
b
=
bson
.
M
{
"$text"
:
bson
.
M
{
"$search"
:
e
}}
default
:
err
=
fmt
.
Errorf
(
"invalid expression"
)
}
}
return
return
v
,
nil
}
}
type
compiler
struct
{
type
compiler
struct
{
...
...
This diff is collapsed.
Click to expand it.
pkg/expr/mongo_test.go
+
6
−
1
View file @
cdfe0757
...
@@ -50,10 +50,15 @@ func TestConvertToMongo(t *testing.T) {
...
@@ -50,10 +50,15 @@ func TestConvertToMongo(t *testing.T) {
{
"time"
,
fmt
.
Sprintf
(
"d > Time.Time('%s')"
,
now
.
Format
(
time
.
RFC3339
)),
nil
,
bson
.
M
{
"d"
:
bson
.
M
{
"$gt"
:
tm
}},
false
},
{
"time"
,
fmt
.
Sprintf
(
"d > Time.Time('%s')"
,
now
.
Format
(
time
.
RFC3339
)),
nil
,
bson
.
M
{
"d"
:
bson
.
M
{
"$gt"
:
tm
}},
false
},
{
"in"
,
"In(s, [1,2,3])"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"in"
,
"In(s, [1,2,3])"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
,
2
,
3
}}},
false
},
{
"in"
,
"In(s, 1)"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
}}},
false
},
{
"in"
,
"In(s, 1)"
,
nil
,
bson
.
M
{
"s"
:
bson
.
M
{
"$in"
:
[]
interface
{}{
1
}}},
false
},
{
"text search or id"
,
"id"
,
nil
,
nil
,
true
},
}
}
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
)
gotB
,
err
:=
ConvertToMongo
(
ctx
,
tt
.
eval
,
tt
.
env
,
nil
)
if
tt
.
wantErr
{
require
.
Error
(
t
,
err
)
return
}
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
tt
.
wantB
,
gotB
)
assert
.
Equal
(
t
,
tt
.
wantB
,
gotB
)
})
})
...
@@ -72,7 +77,7 @@ func BenchmarkConvertToMongo(b *testing.B) {
...
@@ -72,7 +77,7 @@ func BenchmarkConvertToMongo(b *testing.B) {
//fmt.Println(len(exp))
//fmt.Println(len(exp))
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
ConvertToMongo
(
ctx
,
exp
,
nil
,
nil
,
expr
.
Patch
(
&
testVisitor
{}))
_
,
_
=
ConvertToMongo
(
ctx
,
exp
,
nil
,
nil
,
expr
.
Patch
(
&
testVisitor
{}))
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/items/service.go
+
3
−
2
View file @
cdfe0757
...
@@ -54,6 +54,7 @@ type PreSaver interface {
...
@@ -54,6 +54,7 @@ type PreSaver interface {
type
Filter
struct
{
type
Filter
struct
{
ID
[]
string
ID
[]
string
Data
[]
*
filter
.
Filter
Data
[]
*
filter
.
Filter
// DEPRECATED Use Q instead
Search
string
// Поиск, одновременно поддерживается только один запрос
Search
string
// Поиск, одновременно поддерживается только один запрос
Q
[]
string
Q
[]
string
}
}
...
...
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