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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
jio
Commits
29bef154
Commit
29bef154
authored
Mar 25, 2019
by
preetwinder
Committed by
Romain Courteaud
Apr 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unneeded parts
parent
e6afaf04
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
716 deletions
+139
-716
src/jio.storage/indexstorage2.js
src/jio.storage/indexstorage2.js
+84
-179
test/jio.storage/indexstorage2.tests.js
test/jio.storage/indexstorage2.tests.js
+55
-537
No files found.
src/jio.storage/indexstorage2.js
View file @
29bef154
...
@@ -41,108 +41,60 @@
...
@@ -41,108 +41,60 @@
this
.
_version
=
description
.
version
||
undefined
;
this
.
_version
=
description
.
version
||
undefined
;
}
}
function
convertToObject
(
list
,
key
)
{
IndexStorage2
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
i
,
obj
=
{};
return
(
name
===
'
query
'
)
||
(
name
===
'
limit
'
)
||
(
name
===
'
list
'
)
||
for
(
i
=
0
;
i
<
list
.
length
;
i
+=
1
)
{
(
name
===
'
select
'
)
||
this
.
_sub_storage
.
hasCapacity
(
name
);
obj
[
list
[
i
][
key
]]
=
list
[
i
];
};
}
return
obj
;
}
function
keyCount
(
obj
)
{
return
Object
.
keys
(
obj
).
length
;
}
function
union
(
list
)
{
var
result
,
i
,
j
;
if
(
list
.
length
===
0
)
{
return
[];
}
result
=
convertToObject
(
list
[
0
],
'
id
'
);
for
(
i
=
1
;
i
<
list
.
length
;
i
+=
1
)
{
for
(
j
=
0
;
j
<
list
[
i
].
length
;
j
+=
1
)
{
if
(
result
[
list
[
i
][
j
].
id
])
{
if
(
keyCount
(
result
[
list
[
i
][
j
].
id
].
doc
)
<
keyCount
(
list
[
i
][
j
].
doc
))
{
result
[
list
[
i
][
j
].
id
]
=
list
[
i
][
j
];
}
}
else
{
result
[
list
[
i
][
j
].
id
]
=
list
[
i
][
j
];
}
}
}
return
Object
.
values
(
result
);
}
function
intersect
(
list
)
{
function
isSubset
(
array1
,
array2
)
{
var
result
,
temp
=
{},
i
,
j
;
var
i
;
if
(
list
.
length
===
0
)
{
array1
=
new
Set
(
array1
);
return
[];
for
(
i
=
0
;
i
<
array2
.
length
;
i
+=
1
)
{
}
if
(
!
(
array1
.
has
(
array2
[
i
])))
{
result
=
convertToObject
(
list
[
0
],
'
id
'
);
return
false
;
for
(
i
=
1
;
i
<
list
.
length
;
i
+=
1
)
{
for
(
j
=
0
;
j
<
list
[
i
].
length
;
j
+=
1
)
{
if
(
result
[
list
[
i
][
j
].
id
])
{
if
(
keyCount
(
result
[
list
[
i
][
j
].
id
].
doc
)
<
keyCount
(
list
[
i
][
j
].
doc
))
{
temp
[
list
[
i
][
j
].
id
]
=
list
[
i
][
j
];
}
else
{
temp
[
list
[
i
][
j
].
id
]
=
result
[
list
[
i
][
j
].
id
];
}
}
}
}
result
=
temp
;
temp
=
{};
}
}
return
Object
.
values
(
result
);
}
IndexStorage2
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
this_storage_capacity_list
=
[
"
select
"
,
"
list
"
,
"
query
"
,
"
sort
"
,
"
include
"
];
if
(
this_storage_capacity_list
.
indexOf
(
name
)
!==
-
1
)
{
return
true
;
return
true
;
}
}
};
function
handleUpgradeNeeded
(
evt
,
index_keys
)
{
function
handleUpgradeNeeded
(
evt
,
index_keys
)
{
var
db
=
evt
.
target
.
result
,
store
,
i
,
current_indices
;
var
db
=
evt
.
target
.
result
,
store
,
i
,
current_indices
,
required_indices
,
needs_repair
=
false
;
required_indices
=
index_keys
.
map
(
function
(
name
)
{
return
'
Index-
'
+
name
;
});
if
(
!
(
db
.
objectStoreNames
[
0
]))
{
if
(
!
(
db
.
objectStoreNames
[
0
]))
{
store
=
db
.
createObjectStore
(
"
index-store
"
,
{
store
=
db
.
createObjectStore
(
"
index-store
"
,
{
keyPath
:
"
id
"
,
keyPath
:
"
id
"
,
autoIncrement
:
false
autoIncrement
:
false
});
});
current_indices
=
new
Set
();
}
else
{
}
else
{
store
=
evt
.
target
.
transaction
.
objectStore
(
'
index-store
'
);
store
=
evt
.
target
.
transaction
.
objectStore
(
'
index-store
'
);
}
current_indices
=
new
Set
(
store
.
indexNames
);
current_indices
=
new
Set
(
store
.
indexNames
);
for
(
i
=
0
;
i
<
index_keys
.
length
;
i
+=
1
)
{
if
(
!
isSubset
(
store
.
indexNames
,
required_indices
))
{
if
(
!
(
current_indices
.
has
(
index_keys
[
i
])))
{
db
.
deleteObjectStore
(
"
index-store
"
);
db
.
deleteObjectStore
(
"
index-store
"
);
store
=
db
.
createObjectStore
(
"
index-store
"
,
{
store
=
db
.
createObjectStore
(
"
index-store
"
,
{
keyPath
:
"
id
"
,
keyPath
:
"
id
"
,
autoIncrement
:
false
autoIncrement
:
false
});
});
current_indices
=
new
Set
();
current_indices
=
new
Set
();
break
;
needs_repair
=
true
;
}
}
}
}
for
(
i
=
0
;
i
<
index_keys
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
index_keys
.
length
;
i
+=
1
)
{
if
(
!
(
current_indices
.
has
(
'
Index-
'
+
index_key
s
[
i
])))
{
if
(
!
(
current_indices
.
has
(
required_indice
s
[
i
])))
{
store
.
createIndex
(
'
Index-
'
+
index_key
s
[
i
],
store
.
createIndex
(
required_indice
s
[
i
],
'
doc.
'
+
index_keys
[
i
],
{
unique
:
false
});
'
doc.
'
+
index_keys
[
i
],
{
unique
:
false
});
}
}
current_indices
.
delete
(
'
Index-
'
+
index_key
s
[
i
]);
current_indices
.
delete
(
required_indice
s
[
i
]);
}
}
current_indices
=
Array
.
from
(
current_indices
);
current_indices
=
Array
.
from
(
current_indices
);
for
(
i
=
0
;
i
<
current_indices
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
current_indices
.
length
;
i
+=
1
)
{
store
.
deleteIndex
(
current_indices
[
i
]);
store
.
deleteIndex
(
current_indices
[
i
]);
}
}
return
needs_repair
;
}
}
function
waitForOpenIndexedDB
(
db_name
,
version
,
index_keys
,
callback
)
{
function
waitForOpenIndexedDB
(
db_name
,
version
,
index_keys
,
callback
)
{
...
@@ -173,15 +125,14 @@
...
@@ -173,15 +125,14 @@
reject
(
"
Connection to:
"
+
db_name
+
"
timeout
"
);
reject
(
"
Connection to:
"
+
db_name
+
"
timeout
"
);
};
};
// request.onblocked = function (evt) {
request
.
onblocked
=
function
()
{
// console.log("evt", evt);
request
.
result
.
close
();
// request.result.close();
reject
(
"
Connection to:
"
+
db_name
+
"
was blocked
"
);
// reject("Connection to: " + db_name + " was blocked");
};
// };
// Create DB if necessary //
// Create DB if necessary //
request
.
onupgradeneeded
=
function
(
evt
)
{
request
.
onupgradeneeded
=
function
(
evt
)
{
handleUpgradeNeeded
(
evt
,
index_keys
);
this
.
needs_repair
=
handleUpgradeNeeded
(
evt
,
index_keys
);
};
};
request
.
onversionchange
=
function
()
{
request
.
onversionchange
=
function
()
{
...
@@ -190,9 +141,10 @@
...
@@ -190,9 +141,10 @@
};
};
request
.
onsuccess
=
function
()
{
request
.
onsuccess
=
function
()
{
var
context
=
this
;
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
callback
(
request
.
result
);
return
callback
(
request
.
result
,
context
.
needs_repair
);
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
request
.
result
.
close
();
request
.
result
.
close
();
...
@@ -264,114 +216,61 @@
...
@@ -264,114 +216,61 @@
return
doc
;
return
doc
;
}
}
IndexStorage2
.
prototype
.
forceIncludeDocs
=
function
(
result
)
{
IndexStorage2
.
prototype
.
_repairIfNeeded
=
function
(
needs_repair
)
{
var
i
,
get_list
=
{},
context
=
this
;
var
context
=
this
;
return
RSVP
.
Queue
()
return
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
if
(
needs_repair
)
{
if
(
!
(
result
[
i
].
include
))
{
return
context
.
repair
();
get_list
[
result
[
i
].
id
]
=
context
.
_sub_storage
.
get
(
result
[
i
].
id
);
}
}
}
return
RSVP
.
hash
(
get_list
);
})
.
push
(
function
(
get_result
)
{
var
keys
;
result
=
convertToObject
(
result
,
'
id
'
);
keys
=
Object
.
keys
(
get_result
);
for
(
i
=
0
;
i
<
keys
.
length
;
i
+=
1
)
{
result
[
keys
[
i
]].
doc
=
get_result
[
keys
[
i
]];
}
result
=
Object
.
values
(
result
);
return
result
;
})
.
push
(
function
()
{
return
result
;
});
});
};
};
IndexStorage2
.
prototype
.
_runQuery
=
function
(
index
,
value
)
{
IndexStorage2
.
prototype
.
_runQuery
=
function
(
key
,
value
,
limit
)
{
var
context
=
this
;
var
context
=
this
;
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
context
.
_index_keys
,
function
(
db
,
needs_repair
)
{
return
context
.
_repairIfNeeded
(
needs_repair
)
.
push
(
function
()
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
function
(
tx
)
{
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
)
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
)
.
index
(
"
Index-
"
+
index
).
getAll
(
value
))
.
index
(
"
Index-
"
+
key
).
getAll
(
value
,
limit
))
.
then
(
function
(
evt
)
{
.
then
(
function
(
evt
)
{
return
evt
.
target
.
result
;
return
evt
.
target
.
result
;
});
});
});
});
});
});
});
});
};
IndexStorage2
.
prototype
.
_processQueryObject
=
function
(
object
,
include_docs
)
{
var
promise_list
=
[],
context
=
this
,
i
;
include_docs
=
include_docs
||
false
;
return
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
object
.
type
===
"
simple
"
)
{
if
((
context
.
_index_keys
.
indexOf
(
object
.
key
)
===
-
1
))
{
return
context
.
_sub_storage
.
allDocs
({
"
query
"
:
object
.
key
+
"
:
"
+
object
.
value
,
"
include_docs
"
:
include_docs
})
.
push
(
function
(
result
)
{
if
(
include_docs
)
{
result
.
data
.
rows
.
map
(
function
(
v
)
{
v
.
include
=
true
;
});
}
return
result
.
data
.
rows
;
});
}
return
context
.
_runQuery
(
object
.
key
,
object
.
value
);
}
if
(
object
.
type
===
"
complex
"
)
{
for
(
i
=
0
;
i
<
object
.
query_list
.
length
;
i
+=
1
)
{
promise_list
.
push
(
context
.
_processQueryObject
(
object
.
query_list
[
i
],
include_docs
));
}
return
RSVP
.
all
(
promise_list
)
.
then
(
function
(
result
)
{
if
(
object
.
operator
===
"
OR
"
)
{
return
union
(
result
);
}
if
(
object
.
operator
===
"
AND
"
)
{
return
intersect
(
result
);
}
});
});
}
})
};
};
IndexStorage2
.
prototype
.
buildQuery
=
function
(
options
)
{
IndexStorage2
.
prototype
.
buildQuery
=
function
(
options
)
{
var
context
=
this
;
var
context
=
this
,
query
,
select
;
if
(
options
.
query
)
{
select
=
options
.
select_list
;
return
this
.
_processQueryObject
(
parseStringToObject
(
options
.
query
),
if
(
options
.
query
&&
!
options
.
sort_on
&&
!
options
.
include
)
{
options
.
include_docs
)
query
=
parseStringToObject
(
options
.
query
);
.
push
(
function
(
result
)
{
if
(
query
.
type
===
'
simple
'
)
{
if
(
options
.
include_docs
)
{
if
(
context
.
_index_keys
.
indexOf
(
query
.
key
)
!==
-
1
&&
result
=
context
.
forceIncludeDocs
(
result
);
(
!
select
||
isSubset
(
context
.
_index_keys
,
select
)))
{
options
.
select_list
=
undefined
;
return
context
.
_runQuery
(
query
.
key
,
query
.
value
,
options
.
limit
)
}
else
{
options
.
select_list
=
options
.
select_list
||
[];
}
return
result
;
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
return
result
.
map
(
function
(
value
)
{
return
result
.
map
(
function
(
value
)
{
return
{
return
{
"
id
"
:
value
.
id
,
id
:
value
.
id
,
"
value
"
:
filterDocValues
(
value
.
doc
,
options
.
select_list
)
value
:
select
?
filterDocValues
(
value
.
doc
,
select
)
:
{}
};
};
});
});
});
});
}
}
}
}
return
context
.
_sub_storage
.
allDocs
(
options
)
.
push
(
function
(
result
)
{
return
result
.
data
.
rows
;
});
};
};
IndexStorage2
.
prototype
.
get
=
function
()
{
IndexStorage2
.
prototype
.
get
=
function
()
{
...
@@ -381,7 +280,9 @@
...
@@ -381,7 +280,9 @@
IndexStorage2
.
prototype
.
_put
=
function
(
id
,
value
)
{
IndexStorage2
.
prototype
.
_put
=
function
(
id
,
value
)
{
var
context
=
this
;
var
context
=
this
;
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
context
.
_index_keys
,
function
(
db
,
needs_repair
)
{
return
context
.
_repairIfNeeded
(
needs_repair
)
.
push
(
function
()
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
function
(
tx
)
{
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
).
put
({
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
).
put
({
...
@@ -390,6 +291,7 @@
...
@@ -390,6 +291,7 @@
}));
}));
});
});
});
});
});
};
};
IndexStorage2
.
prototype
.
put
=
function
(
id
,
value
)
{
IndexStorage2
.
prototype
.
put
=
function
(
id
,
value
)
{
...
@@ -413,7 +315,9 @@
...
@@ -413,7 +315,9 @@
return
context
.
_sub_storage
.
remove
(
id
)
return
context
.
_sub_storage
.
remove
(
id
)
.
push
(
function
()
{
.
push
(
function
()
{
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
context
.
_index_keys
,
function
(
db
,
needs_repair
)
{
return
context
.
_repairIfNeeded
(
needs_repair
)
.
push
(
function
()
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
function
(
tx
)
{
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
)
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
)
...
@@ -421,6 +325,7 @@
...
@@ -421,6 +325,7 @@
});
});
});
});
});
});
});
};
};
IndexStorage2
.
prototype
.
getAttachment
=
function
()
{
IndexStorage2
.
prototype
.
getAttachment
=
function
()
{
...
...
test/jio.storage/indexstorage2.tests.js
View file @
29bef154
...
@@ -176,6 +176,10 @@
...
@@ -176,6 +176,10 @@
}
}
});
});
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
sort
"
);
};
throws
(
throws
(
function
()
{
function
()
{
this
.
jio
.
hasCapacity
(
"
non
"
);
this
.
jio
.
hasCapacity
(
"
non
"
);
...
@@ -184,16 +188,12 @@
...
@@ -184,16 +188,12 @@
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
equal
(
error
.
message
,
"
Capacity 'non' is not implemented on '
index2
'
"
);
"
Capacity 'non' is not implemented on '
dummystorage3
'
"
);
return
true
;
return
true
;
}
}
);
);
ok
(
this
.
jio
.
hasCapacity
(
"
list
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
query
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
query
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
limit
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
select
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
include
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
sort
"
));
ok
(
this
.
jio
.
hasCapacity
(
"
sort
"
));
});
});
...
@@ -299,55 +299,6 @@
...
@@ -299,55 +299,6 @@
});
});
});
});
test
(
"
use_sub_storage_query is true
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
use_sub_storage_query
:
true
,
index_keys
:
[
"
a
"
,
"
b
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
3
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
list
"
)
||
(
name
===
"
query
"
);
};
DummyStorage3
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
query
:
'
a:"advice"
'
});
return
[
{
id
:
"
21
"
,
value
:
{}}
];
};
RSVP
.
all
([
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
close
"
,
"
b
"
:
45
}),
context
.
jio
.
put
(
"
16
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
5
}),
context
.
jio
.
put
(
"
21
"
,
{
"
a
"
:
"
advice
"
,
"
b
"
:
12
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
a:"advice"
'
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
1
);
deepEqual
(
result
.
data
.
rows
,
[{
id
:
"
21
"
,
value
:
{}}]);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Sub storage capacities are used by default
"
,
function
()
{
test
(
"
Sub storage capacities are used by default
"
,
function
()
{
var
context
=
this
;
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
context
.
jio
=
jIO
.
createJIO
({
...
@@ -408,105 +359,6 @@
...
@@ -408,105 +359,6 @@
});
});
});
});
test
(
"
Sort_on option is given
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
,
"
b
"
,
"
c
"
,
"
d
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
2
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
list
"
);
};
RSVP
.
all
([
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
close
"
,
"
b
"
:
45
,
"
c
"
:
"
78
"
,
"
d
"
:
"
gc4
"
}),
context
.
jio
.
put
(
"
16
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
5
,
"
c
"
:
"
54
"
,
"
d
"
:
"
xf7
"
}),
context
.
jio
.
put
(
"
21
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
83
,
"
c
"
:
"
4
"
,
"
d
"
:
"
gc1
"
}),
context
.
jio
.
put
(
"
7
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
5
,
"
c
"
:
"
26
"
,
"
d
"
:
"
x54
"
}),
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
exhalt
"
,
"
b
"
:
68
,
"
c
"
:
"
28
"
,
"
d
"
:
"
o32
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
sort_on
:
[[
"
a
"
,
"
ascending
"
],
[
"
b
"
,
"
descending
"
],
[
"
d
"
,
"
ascending
"
]]});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
5
);
deepEqual
(
result
.
data
.
rows
,
[
{
"
id
"
:
"
2
"
,
"
value
"
:
{}},
{
"
id
"
:
"
1
"
,
"
value
"
:
{}},
{
"
id
"
:
"
21
"
,
"
value
"
:
{}},
{
"
id
"
:
"
7
"
,
"
value
"
:
{}},
{
"
id
"
:
"
16
"
,
"
value
"
:
{}}
]);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Include docs
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
,
"
b
"
,
"
c
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
2
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
list
"
);
};
RSVP
.
all
([
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
close
"
,
"
b
"
:
45
,
"
c
"
:
"
78
"
,
"
d
"
:
"
gc4
"
}),
context
.
jio
.
put
(
"
16
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
5
,
"
c
"
:
"
54
"
,
"
d
"
:
"
xf7
"
}),
context
.
jio
.
put
(
"
21
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
83
,
"
c
"
:
"
4
"
,
"
d
"
:
"
gc1
"
}),
context
.
jio
.
put
(
"
7
"
,
{
"
a
"
:
"
value
"
,
"
b
"
:
12
,
"
c
"
:
"
26
"
,
"
d
"
:
"
x54
"
}),
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
exhalt
"
,
"
b
"
:
68
,
"
c
"
:
"
28
"
,
"
d
"
:
"
o32
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
include_docs
:
true
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
5
);
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[
{
"
id
"
:
"
2
"
,
"
value
"
:
{
"
a
"
:
"
close
"
,
"
b
"
:
45
,
"
c
"
:
"
78
"
}},
{
"
id
"
:
"
16
"
,
"
value
"
:
{
"
a
"
:
"
value
"
,
"
b
"
:
5
,
"
c
"
:
"
54
"
}},
{
"
id
"
:
"
21
"
,
"
value
"
:
{
"
a
"
:
"
value
"
,
"
b
"
:
83
,
"
c
"
:
"
4
"
}},
{
"
id
"
:
"
7
"
,
"
value
"
:
{
"
a
"
:
"
value
"
,
"
b
"
:
12
,
"
c
"
:
"
26
"
}},
{
"
id
"
:
"
1
"
,
"
value
"
:
{
"
a
"
:
"
exhalt
"
,
"
b
"
:
68
,
"
c
"
:
"
28
"
}}
].
sort
(
idCompare
));
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Simple query matching single object
"
,
function
()
{
test
(
"
Simple query matching single object
"
,
function
()
{
var
context
=
this
;
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
context
.
jio
=
jIO
.
createJIO
({
...
@@ -614,15 +466,16 @@
...
@@ -614,15 +466,16 @@
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
return
capacity
===
'
list
'
;
return
capacity
===
'
list
'
;
};
};
DummyStorage3
.
prototype
.
buildQuery
=
undefined
;
context
.
jio
.
put
(
"
32
"
,
{
"
a
"
:
"
3
"
,
"
b
"
:
"
2
"
})
context
.
jio
.
put
(
"
32
"
,
{
"
a
"
:
"
3
"
,
"
b
"
:
"
2
"
})
.
then
(
function
()
{
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
b:"2"
'
});
return
context
.
jio
.
allDocs
({
query
:
'
b:"2"
'
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
equal
(
error
.
message
,
"
No index for 'b' key and substorage doesn't support queries
"
);
"
Capacity 'query' is not implemented on 'dummystorage3'
"
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
start
();
start
();
...
@@ -649,7 +502,7 @@
...
@@ -649,7 +502,7 @@
return
(
capacity
===
'
list
'
)
||
(
capacity
===
'
query
'
);
return
(
capacity
===
'
list
'
)
||
(
capacity
===
'
query
'
);
};
};
DummyStorage3
.
prototype
.
buildQuery
=
function
(
options
)
{
DummyStorage3
.
prototype
.
buildQuery
=
function
(
options
)
{
equal
(
options
.
query
,
"
a:5
"
);
equal
(
options
.
query
,
'
a: "5"
'
);
return
[{
id
:
"
3
"
,
value
:
{}}];
return
[{
id
:
"
3
"
,
value
:
{}}];
};
};
...
@@ -673,172 +526,6 @@
...
@@ -673,172 +526,6 @@
});
});
});
});
test
(
"
Index is provided for some keys only
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
,
"
b
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
3
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
return
capacity
===
'
query
'
;
};
DummyStorage3
.
prototype
.
buildQuery
=
function
(
options
)
{
equal
(
options
.
query
,
'
c:linear
'
);
return
[{
id
:
"
32
"
,
value
:
{}}];
};
RSVP
.
all
([
context
.
jio
.
put
(
"
32
"
,
{
a
:
"
3
"
,
b
:
"
1
"
,
c
:
"
linear
"
}),
context
.
jio
.
put
(
"
21
"
,
{
a
:
"
8
"
,
b
:
"
1
"
,
c
:
"
obscure
"
}),
context
.
jio
.
put
(
"
3
"
,
{
a
:
"
5
"
,
b
:
"
1
"
,
c
:
"
imminent
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
a: "5" OR c: "linear"
'
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
2
);
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[{
"
id
"
:
"
32
"
,
"
value
"
:
{}},
{
"
id
"
:
"
3
"
,
"
value
"
:
{}}]
.
sort
(
idCompare
));
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Partial sub_storage query is disabled
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
use_sub_storage_query_partial
:
false
,
index_keys
:
[
"
a
"
,
"
b
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
2
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
return
capacity
===
'
query
'
;
};
DummyStorage3
.
prototype
.
buildQuery
=
function
(
options
)
{
equal
(
options
.
query
,
'
c:linear
'
);
return
[{
id
:
"
32
"
,
value
:
{}}];
};
RSVP
.
all
([
context
.
jio
.
put
(
"
32
"
,
{
a
:
"
3
"
,
b
:
"
1
"
,
c
:
"
linear
"
}),
context
.
jio
.
put
(
"
21
"
,
{
a
:
"
8
"
,
b
:
"
1
"
,
c
:
"
obscure
"
}),
context
.
jio
.
put
(
"
3
"
,
{
a
:
"
5
"
,
b
:
"
1
"
,
c
:
"
imminent
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
a: "5" OR c: "linear"
'
});
})
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
);
equal
(
error
.
message
,
"
No index for 'c' key and checking the substorage
"
+
"
for partial queries is not set
"
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
No Query
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
1
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
RSVP
.
all
([
context
.
jio
.
put
(
"
32
"
,
{
"
a
"
:
"
3
"
,
"
b
"
:
"
2
"
}),
context
.
jio
.
put
(
"
21
"
,
{
"
a
"
:
"
6
"
,
"
b
"
:
"
9
"
}),
context
.
jio
.
put
(
"
3
"
,
{
"
a
"
:
"
8
"
,
"
b
"
:
"
5
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
();
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
3
);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Limit without query
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
,
"
b
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
1
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
'
list
'
);
};
RSVP
.
all
([
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
55
"
,
"
b
"
:
"
5
"
}),
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
98
"
,
"
b
"
:
"
3
"
}),
context
.
jio
.
put
(
"
3
"
,
{
"
a
"
:
"
75
"
,
"
b
"
:
"
1
"
}),
context
.
jio
.
put
(
"
8
"
,
{
"
a
"
:
"
43
"
,
"
b
"
:
"
7
"
}),
context
.
jio
.
put
(
"
6
"
,
{
"
a
"
:
"
21
"
,
"
b
"
:
"
2
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
limit
:
3
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
3
);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Limit with query
"
,
function
()
{
test
(
"
Limit with query
"
,
function
()
{
var
context
=
this
;
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
context
.
jio
=
jIO
.
createJIO
({
...
@@ -882,55 +569,7 @@
...
@@ -882,55 +569,7 @@
});
});
});
});
test
(
"
Select without query
"
,
function
()
{
test
(
"
select_list option is preset
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
,
"
b
"
,
"
c
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
2
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
'
list
'
);
};
RSVP
.
all
([
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
try
"
}),
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
98
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
adverse
"
}),
context
.
jio
.
put
(
"
3
"
,
{
"
a
"
:
"
75
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
invite
"
}),
context
.
jio
.
put
(
"
8
"
,
{
"
a
"
:
"
43
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
absolve
"
}),
context
.
jio
.
put
(
"
6
"
,
{
"
a
"
:
"
21
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
defy
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
select_list
:
[
"
a
"
,
"
c
"
]});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
5
);
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[
{
id
:
"
1
"
,
value
:
{
"
a
"
:
"
55
"
,
"
c
"
:
"
try
"
}},
{
id
:
"
2
"
,
value
:
{
"
a
"
:
"
98
"
,
"
c
"
:
"
adverse
"
}},
{
id
:
"
3
"
,
value
:
{
"
a
"
:
"
75
"
,
"
c
"
:
"
invite
"
}},
{
id
:
"
8
"
,
value
:
{
"
a
"
:
"
43
"
,
"
c
"
:
"
absolve
"
}},
{
id
:
"
6
"
,
value
:
{
"
a
"
:
"
21
"
,
"
c
"
:
"
defy
"
}}
].
sort
(
idCompare
));
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Select with query and limit
"
,
function
()
{
var
context
=
this
;
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
type
:
"
index2
"
,
...
@@ -942,14 +581,12 @@
...
@@ -942,14 +581,12 @@
});
});
stop
();
stop
();
expect
(
2
);
expect
(
2
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
return
id
;
};
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
'
list
'
);
return
(
name
===
'
list
'
);
};
};
RSVP
.
all
([
RSVP
.
all
([
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
try
"
}),
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
try
"
}),
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
98
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
adverse
"
}),
context
.
jio
.
put
(
"
2
"
,
{
"
a
"
:
"
98
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
adverse
"
}),
...
@@ -960,14 +597,15 @@
...
@@ -960,14 +597,15 @@
])
])
.
then
(
function
()
{
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
select_list
:
[
"
a
"
,
"
c
"
],
return
context
.
jio
.
allDocs
({
select_list
:
[
"
a
"
,
"
c
"
],
query
:
"
b:2
"
,
limit
:
3
});
query
:
"
b:2
"
});
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
3
);
equal
(
result
.
data
.
total_rows
,
4
);
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[
{
id
:
"
1
"
,
value
:
{
"
a
"
:
"
55
"
,
"
c
"
:
"
try
"
}},
{
id
:
"
1
"
,
value
:
{
"
a
"
:
"
55
"
,
"
c
"
:
"
try
"
}},
{
id
:
"
2
"
,
value
:
{
"
a
"
:
"
98
"
,
"
c
"
:
"
adverse
"
}},
{
id
:
"
2
"
,
value
:
{
"
a
"
:
"
98
"
,
"
c
"
:
"
adverse
"
}},
{
id
:
"
3
"
,
value
:
{
"
a
"
:
"
75
"
,
"
c
"
:
"
invite
"
}}
{
id
:
"
3
"
,
value
:
{
"
a
"
:
"
75
"
,
"
c
"
:
"
invite
"
}},
{
id
:
"
6
"
,
value
:
{
"
a
"
:
"
21
"
,
"
c
"
:
"
defy
"
}}
]);
]);
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
...
@@ -989,11 +627,22 @@
...
@@ -989,11 +627,22 @@
}
}
});
});
stop
();
stop
();
expect
(
2
);
expect
(
3
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
return
id
;
};
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
'
list
'
)
||
(
name
===
'
query
'
)
||
(
name
===
'
select
'
);
};
DummyStorage3
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
select_list
:
[
"
a
"
,
"
b
"
],
query
:
"
a:55
"
});
return
[
{
id
:
"
1
"
,
value
:
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
}},
{
id
:
"
2
"
,
value
:
{
"
a
"
:
"
55
"
,
"
b
"
:
"
5
"
}},
{
id
:
"
3
"
,
value
:
{
"
a
"
:
"
55
"
,
"
b
"
:
"
1
"
}}
];
};
RSVP
.
all
([
RSVP
.
all
([
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
try
"
}),
context
.
jio
.
put
(
"
1
"
,
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
try
"
}),
...
@@ -1004,103 +653,16 @@
...
@@ -1004,103 +653,16 @@
return
context
.
jio
.
allDocs
({
select_list
:
[
"
a
"
,
"
b
"
],
return
context
.
jio
.
allDocs
({
select_list
:
[
"
a
"
,
"
b
"
],
query
:
"
a:55
"
});
query
:
"
a:55
"
});
})
})
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
);
equal
(
error
.
message
,
"
Index key 'b' not found in document
"
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Complex queries
"
,
function
()
{
var
context
=
this
;
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
name
"
,
"
user
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
stop
();
expect
(
10
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
RSVP
.
all
([
context
.
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
envision
"
,
"
url
"
:
"
jio.nexedi.com
"
,
"
user
"
:
"
Mann
"
}),
context
.
jio
.
put
(
"
23
"
,
{
"
name
"
:
"
obscure
"
,
"
url
"
:
"
jio.nexedi.com
"
,
"
user
"
:
"
Hesse
"
}),
context
.
jio
.
put
(
"
5
"
,
{
"
name
"
:
"
envelope
"
,
"
url
"
:
"
renderjs.nexedi.com
"
,
"
user
"
:
"
Mann
"
}),
context
.
jio
.
put
(
"
34
"
,
{
"
name
"
:
"
censure
"
,
"
url
"
:
"
nexedi.com
"
,
"
user
"
:
"
Brahms
"
}),
context
.
jio
.
put
(
"
38
"
,
{
"
name
"
:
"
observe
"
,
"
url
"
:
"
erp5.com
"
,
"
user
"
:
"
Hesse
"
}),
context
.
jio
.
put
(
"
76
"
,
{
"
name
"
:
"
linear
"
,
"
url
"
:
"
vifib.com
"
,
"
user
"
:
"
J Evol
"
}),
context
.
jio
.
put
(
"
14
"
,
{
"
name
"
:
"
obscure
"
,
"
url
"
:
"
re6st.nexedi.com
"
,
"
user
"
:
"
Lietz
"
}),
context
.
jio
.
put
(
"
19
"
,
{
"
name
"
:
"
razor
"
,
"
url
"
:
"
erp5.com
"
,
"
user
"
:
"
Karajan
"
}),
context
.
jio
.
put
(
"
59
"
,
{
"
name
"
:
"
envision
"
,
"
url
"
:
"
nexedi.com
"
,
"
user
"
:
"
Handel
"
}),
context
.
jio
.
put
(
"
31
"
,
{
"
name
"
:
"
obtuse
"
,
"
url
"
:
"
officejs.com
"
,
"
user
"
:
"
Johann
"
}),
context
.
jio
.
put
(
"
45
"
,
{
"
name
"
:
"
repeat
"
,
"
url
"
:
"
slapos.com
"
,
"
user
"
:
"
Specter
"
}),
context
.
jio
.
put
(
"
48
"
,
{
"
name
"
:
"
sever
"
,
"
url
"
:
"
neo.nexedi.com
"
,
"
user
"
:
"
Rienzi
"
}),
context
.
jio
.
put
(
"
72
"
,
{
"
name
"
:
"
organisers
"
,
"
url
"
:
"
vifib.net
"
,
"
user
"
:
"
Parzival
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
"
query
"
:
"
name:razor
"
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
1
);
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
19
"
,
"
value
"
:
{}}]);
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
"
query
"
:
"
name:obscure
"
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
2
);
deepEqual
(
result
.
data
.
rows
.
sort
(),
[{
"
id
"
:
"
23
"
,
"
value
"
:
{}},
{
"
id
"
:
"
14
"
,
"
value
"
:
{}}].
sort
(
idCompare
));
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
"
query
"
:
"
name:envision AND user:Mann
"
});
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
1
);
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
1
"
,
"
value
"
:
{}}]);
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
"
query
"
:
"
name:repeat OR user:Hesse
"
});
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
3
);
equal
(
result
.
data
.
total_rows
,
3
);
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[
[{
"
id
"
:
"
23
"
,
"
value
"
:
{}},
{
"
id
"
:
"
38
"
,
"
value
"
:
{}},
{
id
:
"
1
"
,
value
:
{
"
a
"
:
"
55
"
,
"
b
"
:
"
2
"
}},
{
"
id
"
:
"
45
"
,
"
value
"
:
{}}].
sort
(
idCompare
));
{
id
:
"
2
"
,
value
:
{
"
a
"
:
"
55
"
,
"
b
"
:
"
5
"
}},
})
{
id
:
"
3
"
,
value
:
{
"
a
"
:
"
55
"
,
"
b
"
:
"
1
"
}}
.
then
(
function
()
{
]);
return
context
.
jio
.
allDocs
(
{
"
query
"
:
"
(user:Mann OR user:Hesse) AND name:envelope
"
}
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
.
total_rows
,
1
);
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
5
"
,
"
value
"
:
{}}]);
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
console
.
log
(
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
start
();
start
();
...
@@ -1108,7 +670,7 @@
...
@@ -1108,7 +670,7 @@
});
});
test
(
"
Index keys are modified
"
,
function
()
{
test
(
"
Index keys are modified
"
,
function
()
{
var
context
=
this
;
var
context
=
this
,
dummy_data
;
context
.
jio
=
jIO
.
createJIO
({
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
type
:
"
index2
"
,
database
:
"
index2_test
"
,
database
:
"
index2_test
"
,
...
@@ -1121,12 +683,23 @@
...
@@ -1121,12 +683,23 @@
stop
();
stop
();
expect
(
8
);
expect
(
8
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
dummy_data
=
{
"
32
"
:
{
id
:
"
32
"
,
value
:
{
"
a
"
:
"
3
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
inverse
"
}},
"
5
"
:
{
id
:
"
5
"
,
value
:
{
"
a
"
:
"
6
"
,
"
b
"
:
"
2
"
,
"
c
"
:
"
strong
"
}},
"
14
"
:
{
id
:
"
14
"
,
value
:
{
"
a
"
:
"
67
"
,
"
b
"
:
"
3
"
,
"
c
"
:
"
disolve
"
}}
};
DummyStorage3
.
prototype
.
put
=
function
(
id
,
value
)
{
dummy_data
[
id
]
=
{
id
:
id
,
value
:
value
};
return
id
;
return
id
;
};
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
()
{
DummyStorage3
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
false
;
return
(
name
===
'
list
'
);
};
DummyStorage3
.
prototype
.
buildQuery
=
function
()
{
return
Object
.
values
(
dummy_data
);
};
};
RSVP
.
all
([
RSVP
.
all
([
...
@@ -1161,13 +734,15 @@
...
@@ -1161,13 +734,15 @@
return
context
.
jio
.
allDocs
({
query
:
'
b: "3"
'
});
return
context
.
jio
.
allDocs
({
query
:
'
b: "3"
'
});
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
18
"
,
"
value
"
:
{}}]);
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
14
"
,
"
value
"
:
{}},
{
"
id
"
:
"
18
"
,
"
value
"
:
{}}]);
})
})
.
then
(
function
()
{
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
c: "disolve"
'
});
return
context
.
jio
.
allDocs
({
query
:
'
c: "disolve"
'
});
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
62
"
,
"
value
"
:
{}}]);
deepEqual
(
result
.
data
.
rows
,
[{
"
id
"
:
"
14
"
,
"
value
"
:
{}},
{
"
id
"
:
"
62
"
,
"
value
"
:
{}}]);
})
})
.
then
(
function
()
{
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
a: "3"
'
});
return
context
.
jio
.
allDocs
({
query
:
'
a: "3"
'
});
...
@@ -1201,73 +776,16 @@
...
@@ -1201,73 +776,16 @@
return
context
.
jio
.
allDocs
({
query
:
'
c: "disolve"
'
});
return
context
.
jio
.
allDocs
({
query
:
'
c: "disolve"
'
});
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[{
"
id
"
:
"
1
92
"
,
"
value
"
:
{}},
deepEqual
(
result
.
data
.
rows
.
sort
(
idCompare
),
[{
"
id
"
:
"
1
4
"
,
"
value
"
:
{}},
{
"
id
"
:
"
62
"
,
"
value
"
:
{}}]);
{
"
id
"
:
"
192
"
,
"
value
"
:
{}},
{
"
id
"
:
"
62
"
,
"
value
"
:
{}}]);
})
})
.
then
(
function
()
{
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
query
:
'
b: "3"
'
});
return
context
.
jio
.
allDocs
({
query
:
'
b: "3"
'
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
equal
(
error
.
message
,
"
No index for 'b' key and substorage doesn't support queries
"
);
"
Capacity 'query' is not implemented on 'dummystorage3'
"
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Parallel test
"
,
function
()
{
var
context
=
this
,
i
,
promise_list
=
[],
jio_list
=
[],
index_keys_combinations
;
stop
();
expect
(
1
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
()
{
return
false
;
};
function
random
(
limit
)
{
return
Math
.
floor
(
Math
.
random
()
*
Math
.
floor
(
limit
));
}
index_keys_combinations
=
[[],
[
'
a
'
],
[
'
b
'
],
[
'
c
'
],
[
'
d
'
],
[
'
e
'
],
[
'
a
'
,
'
b
'
],
[
'
a
'
,
'
c
'
],
[
'
a
'
,
'
d
'
],
[
'
a
'
,
'
e
'
],
[
'
b
'
,
'
c
'
],
[
'
b
'
,
'
d
'
],
[
'
b
'
,
'
e
'
],
[
'
c
'
,
'
d
'
],
[
'
c
'
,
'
e
'
],
[
'
a
'
,
'
b
'
,
'
c
'
],
[
'
b
'
,
'
c
'
,
'
d
'
],
[
'
c
'
,
'
d
'
,
'
e
'
],
[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
],
[
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
],
[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
]];
for
(
i
=
0
;
i
<
100
;
i
+=
1
)
{
jio_list
[
i
]
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
index_keys_combinations
[
random
(
index_keys_combinations
.
length
-
1
)],
version
:
i
+
1
,
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
}
for
(
i
=
0
;
i
<
100
;
i
+=
1
)
{
promise_list
.
push
(
jio_list
[
i
].
put
(
"
43
"
,
{
"
a
"
:
"
obscure
"
,
"
b
"
:
"
cr
"
,
"
c
"
:
"
34
"
,
"
d
"
:
"
5454
"
,
"
e
"
:
34
}));
}
RSVP
.
all
(
promise_list
)
.
then
(
function
()
{
return
jio_list
[
99
].
allDocs
();
})
.
then
(
function
(
result
)
{
context
.
jio
=
jio_list
[
99
];
equal
(
result
.
data
.
total_rows
,
1
);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
start
();
start
();
...
...
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