Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Junming
jio
Commits
c1f44a98
Commit
c1f44a98
authored
Dec 29, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Custom operators: fallback to < and = when others are missing
parent
06c4c331
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
0 deletions
+127
-0
src/queries/core/simplequery.js
src/queries/core/simplequery.js
+12
-0
test/queries/keys.eq-lt.tests.js
test/queries/keys.eq-lt.tests.js
+113
-0
test/tests.html
test/tests.html
+2
-0
No files found.
src/queries/core/simplequery.js
View file @
c1f44a98
...
...
@@ -255,6 +255,9 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
if
(
value
.
ne
!==
undefined
)
{
return
value
.
ne
(
comparison_value
);
}
if
(
value
.
eq
!==
undefined
)
{
return
!
value
.
eq
(
comparison_value
);
}
if
(
convertStringToRegExp
(
comparison_value
.
toString
(),
...
...
@@ -311,6 +314,9 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
if
(
value
.
le
!==
undefined
)
{
return
value
.
le
(
comparison_value
);
}
if
(
value
.
lt
!==
undefined
&&
value
.
eq
!==
undefined
)
{
return
value
.
lt
(
comparison_value
)
||
value
.
eq
(
comparison_value
);
}
return
value
<=
comparison_value
;
};
...
...
@@ -335,6 +341,9 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
if
(
value
.
gt
!==
undefined
)
{
return
value
.
gt
(
comparison_value
);
}
if
(
value
.
lt
!==
undefined
&&
value
.
eq
!==
undefined
)
{
return
!
(
value
.
lt
(
comparison_value
)
||
value
.
eq
(
comparison_value
));
}
return
value
>
comparison_value
;
};
...
...
@@ -359,6 +368,9 @@ SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
if
(
value
.
ge
!==
undefined
)
{
return
value
.
ge
(
comparison_value
);
}
if
(
value
.
lt
!==
undefined
)
{
return
!
value
.
lt
(
comparison_value
);
}
return
value
>=
comparison_value
;
};
...
...
test/queries/keys.eq-lt.tests.js
0 → 100644
View file @
c1f44a98
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, complex_queries, jiodate, window, test, ok,
equal, deepEqual, sinon */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
require
(
'
complex_queries
'
),
require
(
'
jiodate
'
));
}
module
(
complex_queries
,
jiodate
);
}([
'
complex_queries
'
,
'
jiodate
'
,
'
qunit
'
],
function
(
complex_queries
,
jiodate
)
{
"
use strict
"
;
module
(
'
Custom keys: fallback to < and = for missing operators
'
);
test
(
'
Stock comparison operators with year precision
'
,
function
()
{
var
doc_list
,
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
twenty ten
'
,
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
},
{
'
identifier
'
:
'
twenty eleven
'
,
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
},
{
'
identifier
'
:
'
twenty twelve
'
,
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
}
];
},
key_schema
=
{
key_set
:
{
date
:
{
read_from
:
'
date
'
,
cast_to
:
jiodate
.
JIODate
}
}
};
jiodate
.
JIODate
.
prototype
.
ne
=
undefined
;
jiodate
.
JIODate
.
prototype
.
le
=
undefined
;
jiodate
.
JIODate
.
prototype
.
gt
=
undefined
;
jiodate
.
JIODate
.
prototype
.
ge
=
undefined
;
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
}
],
'
Match with "date = 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
!=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
},
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date != 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
<
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
}
],
'
Match with "date < 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
<=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
},
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
}
],
'
Match with "date <= 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
>
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date > 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
>=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
},
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date >= 2011" (query tree form)
'
);
});
}));
test/tests.html
View file @
c1f44a98
...
...
@@ -27,6 +27,8 @@
<script
src=
"../lib/moment/moment-2.5.0.js"
></script>
<script
src=
"../src/jio.date/jiodate.js"
></script>
<script
src=
"queries/jiodate.tests.js"
></script>
<script
src=
"queries/jiodate.key.tests.js"
></script>
<script
src=
"queries/keys.eq-lt.tests.js"
></script>
<script
src=
"../src/jio.storage/localstorage.js"
></script>
<script
src=
"queries/localstorage-keys.tests.js"
></script>
...
...
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