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
1753ee5f
Commit
1753ee5f
authored
Aug 05, 2019
by
Romain Courteaud
🐙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP [indexedDB] Add pseudo index support in allDocs
parent
4ca45156
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
5 deletions
+89
-5
src/jio.storage/indexeddbstorage.js
src/jio.storage/indexeddbstorage.js
+17
-5
test/jio.storage/indexeddbstorage.tests.js
test/jio.storage/indexeddbstorage.tests.js
+72
-0
No files found.
src/jio.storage/indexeddbstorage.js
View file @
1753ee5f
...
...
@@ -65,7 +65,7 @@
}
IndexedDBStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
((
name
===
"
list
"
)
||
(
name
===
"
include
"
));
return
((
name
===
"
list
"
)
||
(
name
===
"
include
"
)
||
(
name
===
"
index
"
)
);
};
function
buildKeyPath
(
key_list
)
{
...
...
@@ -268,7 +268,9 @@
IndexedDBStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
result_list
=
[],
context
=
this
;
context
=
this
,
key
=
"
_id
"
,
value
;
function
pushIncludedMetadata
(
cursor
)
{
result_list
.
push
({
...
...
@@ -285,20 +287,30 @@
});
}
if
(
options
.
index
)
{
if
(
context
.
_index_key_list
.
indexOf
(
options
.
index
.
key
)
===
-
1
)
{
throw
new
jIO
.
util
.
jIOError
(
"
IndexedDB: unsupported index '
"
+
options
.
index
.
key
+
"
'
"
,
400
);
}
key
=
INDEX_PREFIX
+
options
.
index
.
key
;
value
=
options
.
index
.
value
;
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
waitForOpenIndexedDB
(
context
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
metadata
"
],
"
readonly
"
,
function
(
tx
)
{
var
key
=
"
_id
"
;
if
(
options
.
include_docs
===
true
)
{
return
waitForAllSynchronousCursor
(
tx
.
objectStore
(
"
metadata
"
).
index
(
key
).
openCursor
(),
tx
.
objectStore
(
"
metadata
"
).
index
(
key
).
openCursor
(
value
),
pushIncludedMetadata
);
}
return
waitForAllSynchronousCursor
(
tx
.
objectStore
(
"
metadata
"
).
index
(
key
).
openKeyCursor
(),
tx
.
objectStore
(
"
metadata
"
).
index
(
key
).
openKeyCursor
(
value
),
pushMetadata
);
});
...
...
test/jio.storage/indexeddbstorage.tests.js
View file @
1753ee5f
...
...
@@ -700,6 +700,78 @@
});
});
test
(
"
Unhandled index
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
3
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
index
:
{
key
:
'
a
'
,
value
:
'
3
'
}});
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
IndexedDB: unsupported index 'a'
"
);
equal
(
error
.
status_code
,
400
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Handled index
"
,
function
()
{
var
context
=
this
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
indexeddb
"
,
database
:
"
qunit
"
,
index_key_list
:
[
'
foo
'
]
});
stop
();
expect
(
1
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
return
RSVP
.
all
([
context
.
jio
.
put
(
"
1
"
,
{
"
foo
"
:
"
bar
"
}),
context
.
jio
.
put
(
"
2
"
,
{
"
foo
"
:
"
bar2
"
}),
context
.
jio
.
put
(
"
3
"
,
{
"
foo2
"
:
"
bar
"
}),
context
.
jio
.
put
(
"
4
"
,
{
"
foo
"
:
"
bar
"
})
]);
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
index
:
{
key
:
'
foo
'
,
value
:
'
bar
'
}});
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
1
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
4
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
2
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// indexeddbStorage.get
/////////////////////////////////////////////////////////////////
...
...
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