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
c817194b
Commit
c817194b
authored
Mar 12, 2019
by
preetwinder
Committed by
Romain Courteaud
Apr 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tests, new tests and fix index2 issues
parent
4c8d5307
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
211 additions
and
182 deletions
+211
-182
src/jio.storage/indexstorage2.js
src/jio.storage/indexstorage2.js
+47
-39
test/jio.storage/indexstorage2.tests.js
test/jio.storage/indexstorage2.tests.js
+164
-143
No files found.
src/jio.storage/indexstorage2.js
View file @
c817194b
...
@@ -33,11 +33,11 @@
...
@@ -33,11 +33,11 @@
}
}
this
.
_sub_storage
=
jIO
.
createJIO
(
description
.
sub_storage
);
this
.
_sub_storage
=
jIO
.
createJIO
(
description
.
sub_storage
);
this
.
_database_name
=
"
jio:
"
+
description
.
database
;
this
.
_database_name
=
"
jio:
"
+
description
.
database
;
this
.
_index_keys
=
description
.
index_keys
;
this
.
_index_keys
=
description
.
index_keys
||
[]
;
}
}
IndexStorage2
.
prototype
.
hasCapacity
=
function
(
name
)
{
IndexStorage2
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
((
name
===
"
list
"
)
||
(
name
===
"
query
"
));
return
((
name
===
"
list
"
)
||
(
name
===
"
query
"
))
||
(
name
===
"
limit
"
)
;
};
};
function
handleUpgradeNeeded
(
evt
,
index_keys
)
{
function
handleUpgradeNeeded
(
evt
,
index_keys
)
{
...
@@ -160,26 +160,43 @@
...
@@ -160,26 +160,43 @@
});
});
}
}
IndexStorage2
.
prototype
.
_runQuery
=
function
(
index
,
value
)
{
function
filterDocValues
(
doc
,
keys
)
{
var
filtered_doc
=
{},
i
;
for
(
i
=
0
;
i
<
keys
.
length
;
i
+=
1
)
{
if
(
doc
[
keys
[
i
]])
{
filtered_doc
[
keys
[
i
]]
=
doc
[
keys
[
i
]];
}
else
{
throw
new
jIO
.
util
.
jIOError
(
"
Index key '
"
+
keys
[
i
]
+
"
' not found in document
"
,
404
);
}
}
return
filtered_doc
;
}
IndexStorage2
.
prototype
.
_runQuery
=
function
(
index
,
value
,
limit
)
{
var
context
=
this
;
var
context
=
this
;
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
if
((
context
.
_index_keys
.
indexOf
(
index
)
===
-
1
))
{
if
((
context
.
_index_keys
.
indexOf
(
index
)
===
-
1
))
{
if
(
context
.
_sub_storage
.
hasCapacity
(
"
query
"
))
{
try
{
return
context
.
_sub_storage
.
buildQuery
(
context
.
_sub_storage
.
hasCapacity
(
"
query
"
);
{
"
query
"
:
index
+
"
:
"
+
value
}
}
catch
(
error
)
{
)
throw
new
jIO
.
util
.
jIOError
(
.
then
(
function
(
result
)
{
"
No index for this key and substorage doesn't support queries
"
return
result
;
);
});
}
}
return
context
.
_sub_storage
.
buildQuery
(
{
"
query
"
:
index
+
"
:
"
+
value
}
);
}
}
return
waitForOpenIndexedDB
(
context
.
_database_name
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_index_keys
,
context
.
_index_keys
,
function
(
db
)
{
function
(
db
)
{
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-
"
+
index
).
getAll
(
value
,
limit
))
.
then
(
function
(
evt
)
{
.
then
(
function
(
evt
)
{
return
evt
.
target
.
result
;
return
evt
.
target
.
result
;
});
});
...
@@ -188,12 +205,12 @@
...
@@ -188,12 +205,12 @@
});
});
};
};
IndexStorage2
.
prototype
.
_processQueryObject
=
function
(
object
)
{
IndexStorage2
.
prototype
.
_processQueryObject
=
function
(
object
,
limit
)
{
var
promise_list
=
[],
context
=
this
,
i
,
j
,
query_result
=
new
Set
();
var
promise_list
=
[],
context
=
this
,
i
,
j
,
query_result
=
new
Set
();
return
RSVP
.
Queue
()
return
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
if
(
object
.
type
===
"
simple
"
)
{
if
(
object
.
type
===
"
simple
"
)
{
return
context
.
_runQuery
(
object
.
key
,
object
.
value
);
return
context
.
_runQuery
(
object
.
key
,
object
.
value
,
limit
);
}
}
if
(
object
.
type
===
"
complex
"
)
{
if
(
object
.
type
===
"
complex
"
)
{
for
(
i
=
0
;
i
<
object
.
query_list
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
object
.
query_list
.
length
;
i
+=
1
)
{
...
@@ -234,18 +251,20 @@
...
@@ -234,18 +251,20 @@
IndexStorage2
.
prototype
.
buildQuery
=
function
(
options
)
{
IndexStorage2
.
prototype
.
buildQuery
=
function
(
options
)
{
var
context
=
this
;
var
context
=
this
;
if
(
options
.
query
)
{
if
(
options
.
query
)
{
return
this
.
_processQueryObject
(
parseStringToObject
(
options
.
query
))
return
this
.
_processQueryObject
(
parseStringToObject
(
options
.
query
),
.
then
(
function
(
result
)
{
options
.
limit
)
.
push
(
function
(
result
)
{
return
result
.
map
(
function
(
value
)
{
return
result
.
map
(
function
(
value
)
{
return
{
"
id
"
:
value
.
id
,
"
value
"
:
{}
};
return
{
"
id
"
:
value
.
id
,
"
value
"
:
{}
};
});
});
});
});
}
}
return
waitForOpenIndexedDB
(
context
.
_database_name
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_index_keys
,
context
.
_index_keys
,
function
(
db
)
{
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
function
(
tx
)
{
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
).
getAll
())
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
)
.
getAll
(
undefined
,
options
.
limit
))
.
then
(
function
(
evt
)
{
.
then
(
function
(
evt
)
{
return
evt
.
target
.
result
.
map
(
function
(
value
)
{
return
evt
.
target
.
result
.
map
(
function
(
value
)
{
return
{
"
id
"
:
value
.
id
,
"
value
"
:
{}
};
return
{
"
id
"
:
value
.
id
,
"
value
"
:
{}
};
...
@@ -259,29 +278,18 @@
...
@@ -259,29 +278,18 @@
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
);
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
IndexStorage2
.
prototype
.
_filter_doc_values
=
function
(
doc
,
keys
)
{
var
filtered_doc
=
{},
i
;
for
(
i
=
0
;
i
<
keys
.
length
;
i
+=
1
)
{
filtered_doc
[
keys
[
i
]]
=
doc
[
keys
[
i
]];
}
return
filtered_doc
;
};
IndexStorage2
.
prototype
.
put
=
function
(
id
,
value
)
{
IndexStorage2
.
prototype
.
put
=
function
(
id
,
value
)
{
var
context
=
this
;
var
context
=
this
;
return
context
.
_sub_storage
.
put
(
id
,
value
)
return
context
.
_sub_storage
.
put
(
id
,
value
)
.
push
(
function
(
result
)
{
.
push
(
function
()
{
return
waitForOpenIndexedDB
(
context
.
_database_name
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_index_keys
,
context
.
_index_keys
,
function
(
db
)
{
function
(
db
)
{
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
({
"
id
"
:
id
,
"
id
"
:
id
,
"
doc
"
:
context
.
_filter_doc_values
(
value
,
context
.
_index_keys
)
"
doc
"
:
filterDocValues
(
value
,
context
.
_index_keys
)
}))
}));
.
then
(
function
()
{
return
result
;
});
});
});
});
});
});
});
...
@@ -291,13 +299,13 @@
...
@@ -291,13 +299,13 @@
var
context
=
this
;
var
context
=
this
;
return
context
.
_sub_storage
.
post
(
value
)
return
context
.
_sub_storage
.
post
(
value
)
.
push
(
function
(
id
)
{
.
push
(
function
(
id
)
{
return
waitForOpenIndexedDB
(
context
.
_database_name
,
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_index_keys
,
context
.
_index_keys
,
function
(
db
)
{
function
(
db
)
{
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
({
"
id
"
:
id
,
"
id
"
:
id
,
"
doc
"
:
context
.
_filter_doc_v
alues
(
value
,
context
.
_index_keys
)
"
doc
"
:
filterDocV
alues
(
value
,
context
.
_index_keys
)
}))
}))
.
then
(
function
()
{
.
then
(
function
()
{
return
id
;
return
id
;
...
...
test/jio.storage/indexstorage2.tests.js
View file @
c817194b
This diff is collapsed.
Click to expand it.
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