Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurélien Vermylen
jio
Commits
5b0db3bd
Commit
5b0db3bd
authored
Dec 30, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Custom operators: default_match -> equal_match
parent
87caa37b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
27 deletions
+36
-27
src/queries/core/simplequery.js
src/queries/core/simplequery.js
+10
-14
test/queries/key-schema.tests.js
test/queries/key-schema.tests.js
+5
-5
test/queries/keys.tests.js
test/queries/keys.tests.js
+21
-8
No files found.
src/queries/core/simplequery.js
View file @
5b0db3bd
...
...
@@ -58,7 +58,6 @@ function SimpleQuery(spec, key_schema) {
* @optional
*/
this
.
operator
=
spec
.
operator
||
"
=
"
;
this
.
_spec
=
spec
.
operator
;
/**
* Key of the object which refers to the value to compare
...
...
@@ -92,7 +91,7 @@ var checkKey = function (key) {
switch
(
prop
)
{
case
'
read_from
'
:
case
'
cast_to
'
:
case
'
default
_match
'
:
case
'
equal
_match
'
:
break
;
default
:
throw
new
TypeError
(
"
Custom key has unknown property '
"
+
...
...
@@ -108,7 +107,7 @@ var checkKey = function (key) {
*/
SimpleQuery
.
prototype
.
match
=
function
(
item
,
wildcard_character
)
{
var
object_value
=
null
,
default
_match
=
null
,
equal
_match
=
null
,
cast_to
=
null
,
matchMethod
=
null
,
value
=
null
,
...
...
@@ -124,20 +123,17 @@ SimpleQuery.prototype.match = function (item, wildcard_character) {
checkKey
(
key
);
object_value
=
item
[
key
.
read_from
];
default_match
=
key
.
default
_match
;
equal_match
=
key
.
equal
_match
;
//
default
_match can be a string
if
(
typeof
default
_match
===
'
string
'
)
{
// XXX raise error if
default
_match not in match_lookup
default_match
=
this
.
_key_schema
.
match_lookup
[
default
_match
];
//
equal
_match can be a string
if
(
typeof
equal
_match
===
'
string
'
)
{
// XXX raise error if
equal
_match not in match_lookup
equal_match
=
this
.
_key_schema
.
match_lookup
[
equal
_match
];
}
// default_match overrides the default '=' operator
matchMethod
=
(
default_match
||
matchMethod
);
// but an explicit operator: parameter overrides default_match
if
(
this
.
_spec
&&
this
.
_spec
.
operator
)
{
matchMethod
=
this
[
this
.
operator
];
// equal_match overrides the default '=' operator
if
(
equal_match
!==
undefined
)
{
matchMethod
=
(
this
.
operator
===
'
=
'
)
?
equal_match
:
matchMethod
;
}
value
=
this
.
value
;
...
...
test/queries/key-schema.tests.js
View file @
5b0db3bd
...
...
@@ -58,7 +58,7 @@
key_set
:
{
case_insensitive_identifier
:
{
read_from
:
'
identifier
'
,
default
_match
:
function
(
object_value
,
value
,
wildcard_character
)
{
equal
_match
:
function
(
object_value
,
value
,
wildcard_character
)
{
// XXX do this with a regexp and wildcard support
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
...
...
@@ -66,21 +66,21 @@
date_day
:
{
read_from
:
'
date
'
,
cast_to
:
'
dateType
'
,
default
_match
:
'
sameDay
'
equal
_match
:
'
sameDay
'
},
date_month
:
{
read_from
:
'
date
'
,
cast_to
:
'
dateType
'
,
default
_match
:
'
sameMonth
'
equal
_match
:
'
sameMonth
'
},
date_year
:
{
read_from
:
'
date
'
,
cast_to
:
'
dateType
'
,
default
_match
:
'
sameYear
'
equal
_match
:
'
sameYear
'
},
translated_state
:
{
read_from
:
'
state
'
,
default
_match
:
'
equalState
'
equal
_match
:
'
equalState
'
}
}
};
...
...
test/queries/keys.tests.js
View file @
5b0db3bd
...
...
@@ -31,7 +31,7 @@
},
case_insensitive_identifier
:
{
read_from
:
'
identifier
'
,
default
_match
:
function
(
object_value
,
value
,
wildcard_character
)
{
equal
_match
:
function
(
object_value
,
value
,
wildcard_character
)
{
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
}
...
...
@@ -105,17 +105,17 @@
day
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
default
_match
:
sameDay
equal
_match
:
sameDay
},
month
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
default
_match
:
sameMonth
equal
_match
:
sameMonth
},
year
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
default
_match
:
sameYear
equal
_match
:
sameYear
}
};
...
...
@@ -250,7 +250,7 @@
});
test
(
'
Simple Key with both
default
_match and operator attributes
'
,
function
()
{
test
(
'
Simple Key with both
equal
_match and operator attributes
'
,
function
()
{
var
doc_list
,
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
...
...
@@ -261,7 +261,7 @@
mydate
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
default
_match
:
function
alwaysTrue
()
{
return
true
;
}
equal
_match
:
function
alwaysTrue
()
{
return
true
;
}
}
};
...
...
@@ -282,13 +282,25 @@
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>
=
'
,
operator
:
'
=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
"
The catch-all filter overrides the default '=' operator
"
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
An explicit operator should override the catch-all filter
'
);
});
...
...
@@ -388,7 +400,7 @@
keys
=
{
translated_state
:
{
read_from
:
'
state
'
,
default
_match
:
equalState
equal
_match
:
equalState
}
};
...
...
@@ -416,6 +428,7 @@
],
'
It should be possible to look for a translated string with operator =
'
);
// XXX not implemented yet
// doc_list = docList();
// complex_queries.QueryFactory.create({
// type: 'simple',
...
...
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