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
Kirill Smelkov
jio
Commits
1e991dc6
Commit
1e991dc6
authored
Feb 16, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add QueryStorage tests.
parent
41b69b80
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
677 additions
and
934 deletions
+677
-934
src/jio.storage/querystorage.js
src/jio.storage/querystorage.js
+26
-154
test/jio.storage/querystorage.tests.js
test/jio.storage/querystorage.tests.js
+636
-769
test/tests.html
test/tests.html
+15
-11
No files found.
src/jio.storage/querystorage.js
View file @
1e991dc6
/*jslint nomen: true
, maxlen: 200
*/
/*jslint nomen: true*/
/*global RSVP*/
/*global RSVP*/
(
function
(
jIO
)
{
(
function
(
jIO
,
RSVP
)
{
"
use strict
"
;
"
use strict
"
;
/**
/**
...
@@ -33,18 +33,10 @@
...
@@ -33,18 +33,10 @@
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
QueryStorage
.
prototype
.
removeAttachment
=
function
()
{
QueryStorage
.
prototype
.
removeAttachment
=
function
()
{
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
/**
* Retrieve documents.
* This method performs an .allDocs() call on the substorage,
* retrieving everything, then runs a query on the result.
*
* @method allDocs
* @param {Object} command The given parameters
* @param {Object} options The command options
*/
QueryStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
QueryStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
if
(
name
===
"
list
"
)
{
if
(
name
===
"
list
"
)
{
return
this
.
_sub_storage
.
hasCapacity
(
name
);
return
this
.
_sub_storage
.
hasCapacity
(
name
);
...
@@ -54,7 +46,6 @@
...
@@ -54,7 +46,6 @@
QueryStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
QueryStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
substorage
=
this
.
_sub_storage
,
var
substorage
=
this
.
_sub_storage
,
context
=
this
,
context
=
this
,
// sub_query_result,
sub_options
=
{},
sub_options
=
{},
is_manual_query_needed
=
false
,
is_manual_query_needed
=
false
,
is_manual_include_needed
=
false
;
is_manual_include_needed
=
false
;
...
@@ -63,17 +54,22 @@
...
@@ -63,17 +54,22 @@
// Can substorage handle the queries if needed?
// Can substorage handle the queries if needed?
try
{
try
{
if
(((
options
.
query
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
query
"
)))
&&
if
(((
options
.
query
===
undefined
)
||
((
options
.
sort_on
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
sort
"
)))
&&
(
substorage
.
hasCapacity
(
"
query
"
)))
&&
((
options
.
select_list
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
select
"
)))
&&
((
options
.
sort_on
===
undefined
)
||
((
options
.
limit
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
limit
"
))))
{
(
substorage
.
hasCapacity
(
"
sort
"
)))
&&
((
options
.
select_list
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
select
"
)))
&&
((
options
.
limit
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
limit
"
))))
{
sub_options
.
query
=
options
.
query
;
sub_options
.
query
=
options
.
query
;
sub_options
.
sort_on
=
options
.
sort_on
;
sub_options
.
sort_on
=
options
.
sort_on
;
sub_options
.
select_list
=
options
.
select_list
;
sub_options
.
select_list
=
options
.
select_list
;
sub_options
.
limit
=
options
.
limit
;
sub_options
.
limit
=
options
.
limit
;
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
is_manual_query_needed
=
true
;
is_manual_query_needed
=
true
;
}
else
{
}
else
{
throw
error
;
throw
error
;
...
@@ -82,18 +78,20 @@
...
@@ -82,18 +78,20 @@
// Can substorage include the docs if needed?
// Can substorage include the docs if needed?
try
{
try
{
if
((
is_manual_query_needed
||
(
options
.
include_docs
===
true
))
&&
(
!
substorage
.
hasCapacity
(
"
include
"
)))
{
if
((
is_manual_query_needed
||
sub_options
.
include_docs
=
options
.
include_docs
;
(
options
.
include_docs
===
true
))
&&
(
substorage
.
hasCapacity
(
"
include
"
)))
{
sub_options
.
include_docs
=
true
;
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
is_manual_include_needed
=
true
;
is_manual_include_needed
=
true
;
}
else
{
}
else
{
throw
error
;
throw
error
;
}
}
}
}
return
substorage
.
buildQuery
(
sub_options
)
return
substorage
.
buildQuery
(
sub_options
)
// Include docs if needed
// Include docs if needed
...
@@ -106,7 +104,8 @@
...
@@ -106,7 +104,8 @@
return
substorage
.
get
({
"
_id
"
:
result
[
j
].
id
})
return
substorage
.
get
({
"
_id
"
:
result
[
j
].
id
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
// Document may have been dropped after listing
// Document may have been dropped after listing
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
;
return
;
}
}
throw
error
;
throw
error
;
...
@@ -135,6 +134,7 @@
...
@@ -135,6 +134,7 @@
result
=
original_result
;
result
=
original_result
;
}
}
return
result
;
return
result
;
})
})
// Manual query if needed
// Manual query if needed
...
@@ -143,7 +143,6 @@
...
@@ -143,7 +143,6 @@
len
,
len
,
i
;
i
;
if
(
is_manual_query_needed
)
{
if
(
is_manual_query_needed
)
{
// sub_query_result = result;
len
=
result
.
length
;
len
=
result
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
data_rows
.
push
(
result
[
i
].
doc
);
data_rows
.
push
(
result
[
i
].
doc
);
...
@@ -151,7 +150,8 @@
...
@@ -151,7 +150,8 @@
if
(
options
.
select_list
)
{
if
(
options
.
select_list
)
{
options
.
select_list
.
push
(
"
_id
"
);
options
.
select_list
.
push
(
"
_id
"
);
}
}
result
=
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
context
.
_key_schema
).
result
=
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
context
.
_key_schema
).
exec
(
data_rows
,
options
);
exec
(
data_rows
,
options
);
}
}
return
result
;
return
result
;
...
@@ -186,137 +186,9 @@
...
@@ -186,137 +186,9 @@
return
result
;
return
result
;
});
});
// if (options.include_docs) {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "doc": docs[filtered_docs[i]._id],
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// } else {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// }
// response.data.rows = filtered_docs;
// response.data.total_rows = filtered_docs.length;
// return response;
// });
// return jIO.QueryFactory.create(options.query || "", that._key_schema).
// exec(data_rows, options).
// then(function (filtered_docs) {
// // reconstruct filtered rows, preserving the order from docs
// if (options.include_docs) {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "doc": docs[filtered_docs[i]._id],
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// } else {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// }
// response.data.rows = filtered_docs;
// response.data.total_rows = filtered_docs.length;
// return response;
// });
}
}
// }).then(function (response) {
//
// ((options.include_docs === undefined) || context.hasCapacity("include")) &&
// }
//
// return context.buildQuery.apply(context, arguments);
// }
//
// // // we need the full documents in order to perform the query, will
// // // remove them later if they were not required.
// // include_docs = (options.include_docs || options.query) ? true : false;
//
// console.log("QueryStorage: calling substorage buildQuery");
// return substorage.buildQuery.apply(substorage, arguments);
// return substorage.buildQuery.apply(substorage, arguments)
// .push(function (result) {
// });
// substorage.allDocs({
// "include_docs": include_docs
// }).then(function (response) {
//
// var data_rows = response.data.rows, docs = {}, row, i, l;
//
// if (!include_docs) {
// return response;
// }
//
// if (options.include_docs) {
// for (i = 0, l = data_rows.length; i < l; i += 1) {
// row = data_rows[i];
// docs[row.id] = JSON.parse(JSON.stringify(row.doc));
// row.doc._id = row.id;
// data_rows[i] = row.doc;
// }
// } else {
// for (i = 0, l = data_rows.length; i < l; i += 1) {
// row = data_rows[i];
// row.doc._id = row.id;
// data_rows[i] = row.doc;
// }
// }
//
// if (options.select_list) {
// options.select_list.push("_id");
// }
//
// return jIO.QueryFactory.create(options.query || "", that._key_schema).
// exec(data_rows, options).
// then(function (filtered_docs) {
// // reconstruct filtered rows, preserving the order from docs
// if (options.include_docs) {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "doc": docs[filtered_docs[i]._id],
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// } else {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// }
// response.data.rows = filtered_docs;
// response.data.total_rows = filtered_docs.length;
// return response;
// });
//
// }).then(command.success, command.error, command.notify);
};
};
jIO
.
addStorage
(
'
query
'
,
QueryStorage
);
jIO
.
addStorage
(
'
query
'
,
QueryStorage
);
}(
jIO
));
}(
jIO
,
RSVP
));
test/jio.storage/querystorage.tests.js
View file @
1e991dc6
This diff is collapsed.
Click to expand it.
test/tests.html
View file @
1e991dc6
...
@@ -3,13 +3,14 @@
...
@@ -3,13 +3,14 @@
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<title>
JIO Qunit/Sinon Unit Tests
</title>
<title>
JIO Qunit/Sinon Unit Tests
</title>
<script
src=
"../node_modules/rsvp/dist/rsvp-2.0.4.js"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<link
rel=
"stylesheet"
href=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.css"
type=
"text/css"
media=
"screen"
/>
<link
rel=
"stylesheet"
href=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.css"
type=
"text/css"
media=
"screen"
/>
<script
src=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/rsvp/dist/rsvp-2.0.4.js"
></script>
<script
src=
"../node_modules/sinon/pkg/sinon.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/sinon/pkg/sinon.js"
type=
"text/javascript"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<
script
src=
"html5.js"
></script
>
<
!--script src="html5.js"></script--
>
<!--script src="jio/util.js"></script-->
<!--script src="jio/util.js"></script-->
<!--script src="jio/fakestorage.js"></script>
<!--script src="jio/fakestorage.js"></script>
<script src="jio/tests.js"></script-->
<script src="jio/tests.js"></script-->
...
@@ -22,24 +23,27 @@
...
@@ -22,24 +23,27 @@
<script
src=
"queries/jiodate.tests.js"
></script>
<script
src=
"queries/jiodate.tests.js"
></script>
<script
src=
"queries/key-jiodate.tests.js"
></script>
<script
src=
"queries/key-jiodate.tests.js"
></script>
<
script
src=
"queries/key-localstorage.tests.js"
></script
>
<
!--script src="queries/key-localstorage.tests.js"></script--
>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/memorystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<!--script src="jio.storage/localstorage.tests.js"></script>
<script src="jio.storage/davstorage.tests.js"></script>
<script src="jio.storage/davstorage.tests.js"></script>
<script
src=
"jio.storage/indexeddbstorage.tests.js"
></script>
<script src="jio.storage/unionstorage.tests.js"></script>
<script src="jio.storage/unionstorage.tests.js"></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script src="jio.storage/querystorage.tests.js"></script-->
<script
src=
"jio.storage/dropboxstorage.tests.js"
></script>
<!--script src="jio.storage/indexeddbstorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script-->
<!--script src="jio.storage/dropboxstorage.tests.js"></script-->
<!--script src="../lib/jquery/jquery.min.js"></script>
<!--script src="../lib/jquery/jquery.min.js"></script>
<script src="../src/jio.storage/xwikistorage.js"></script>
<script src="../src/jio.storage/xwikistorage.js"></script>
<script src="jio.storage/xwikistorage.tests.js"></script-->
<script src="jio.storage/xwikistorage.tests.js"></script-->
<!--script src="../src/jio.storage/indexstorage.js"></script>
<script src="jio.storage/indexstorage.tests.js"></script>
<script src="../src/jio.storage/gidstorage.js"></script>
<
!--
script src="../src/jio.storage/gidstorage.js"></script>
<script src="../test/jio.storage/gidstorage.tests.js"></script>
<script src="../test/jio.storage/gidstorage.tests.js"></script>
<script src="../src/jio.storage/revisionstorage.js"></script>
<script src="../src/jio.storage/revisionstorage.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