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
Mukul
jio
Commits
ee8a65fa
Commit
ee8a65fa
authored
Jun 16, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IndexedDB: add support to include_docs
parent
1ab6a5f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
156 additions
and
3 deletions
+156
-3
src/jio.storage/indexeddbstorage.js
src/jio.storage/indexeddbstorage.js
+13
-2
test/jio.storage/indexeddbstorage.tests.js
test/jio.storage/indexeddbstorage.tests.js
+143
-1
No files found.
src/jio.storage/indexeddbstorage.js
View file @
ee8a65fa
...
...
@@ -46,7 +46,7 @@
}
IndexedDBStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
list
"
);
return
(
(
name
===
"
list
"
)
||
(
name
===
"
include
"
)
);
};
function
buildKeyPath
(
key_list
)
{
...
...
@@ -170,9 +170,16 @@
return
new
RSVP
.
Promise
(
resolver
);
}
IndexedDBStorage
.
prototype
.
buildQuery
=
function
()
{
IndexedDBStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
result_list
=
[];
function
pushIncludedMetadata
(
cursor
)
{
result_list
.
push
({
"
id
"
:
cursor
.
key
,
"
value
"
:
cursor
.
value
.
doc
});
}
function
pushMetadata
(
cursor
)
{
result_list
.
push
({
"
id
"
:
cursor
.
key
,
...
...
@@ -182,6 +189,10 @@
return
openIndexedDB
(
this
)
.
push
(
function
(
db
)
{
var
tx
=
openTransaction
(
db
,
[
"
metadata
"
],
"
readonly
"
);
if
(
options
.
include_docs
===
true
)
{
return
handleCursor
(
tx
.
objectStore
(
"
metadata
"
).
index
(
"
_id
"
)
.
openCursor
(),
pushIncludedMetadata
);
}
return
handleCursor
(
tx
.
objectStore
(
"
metadata
"
).
index
(
"
_id
"
)
.
openKeyCursor
(),
pushMetadata
);
})
...
...
test/jio.storage/indexeddbstorage.tests.js
View file @
ee8a65fa
...
...
@@ -79,6 +79,7 @@
this
.
spy_create_index
=
sinon
.
spy
(
IDBObjectStore
.
prototype
,
"
createIndex
"
);
this
.
spy_key_cursor
=
sinon
.
spy
(
IDBIndex
.
prototype
,
"
openKeyCursor
"
);
this
.
spy_cursor
=
sinon
.
spy
(
IDBIndex
.
prototype
,
"
openCursor
"
);
},
teardown
:
function
()
{
this
.
spy_open
.
restore
();
...
...
@@ -95,13 +96,15 @@
delete
this
.
spy_create_index
;
this
.
spy_key_cursor
.
restore
();
delete
this
.
spy_key_cursor
;
this
.
spy_cursor
.
restore
();
delete
this
.
spy_cursor
;
}
});
test
(
"
spy indexedDB usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
3
0
);
expect
(
3
1
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
...
...
@@ -186,6 +189,108 @@
ok
(
context
.
spy_key_cursor
.
calledOnce
,
"
key_cursor count
"
+
context
.
spy_key_cursor
.
callCount
);
equal
(
context
.
spy_cursor
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
spy indexedDB usage with include_docs
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
31
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
include_docs
:
true
});
})
.
then
(
function
()
{
ok
(
context
.
spy_open
.
calledOnce
,
"
open count
"
+
context
.
spy_open
.
callCount
);
equal
(
context
.
spy_open
.
firstCall
.
args
[
0
],
"
jio:qunit
"
,
"
open first argument
"
);
equal
(
context
.
spy_create_store
.
callCount
,
3
,
"
createObjectStore count
"
);
equal
(
context
.
spy_create_store
.
firstCall
.
args
[
0
],
"
metadata
"
,
"
first createObjectStore first argument
"
);
deepEqual
(
context
.
spy_create_store
.
firstCall
.
args
[
1
],
{
keyPath
:
"
_id
"
,
autoIncrement
:
false
},
"
first createObjectStore second argument
"
);
equal
(
context
.
spy_create_store
.
secondCall
.
args
[
0
],
"
attachment
"
,
"
second createObjectStore first argument
"
);
deepEqual
(
context
.
spy_create_store
.
secondCall
.
args
[
1
],
{
keyPath
:
"
_key_path
"
,
autoIncrement
:
false
},
"
second createObjectStore second argument
"
);
equal
(
context
.
spy_create_store
.
thirdCall
.
args
[
0
],
"
blob
"
,
"
third createObjectStore first argument
"
);
deepEqual
(
context
.
spy_create_store
.
thirdCall
.
args
[
1
],
{
keyPath
:
"
_key_path
"
,
autoIncrement
:
false
},
"
third createObjectStore second argument
"
);
equal
(
context
.
spy_create_index
.
callCount
,
4
,
"
createIndex count
"
);
equal
(
context
.
spy_create_index
.
firstCall
.
args
[
0
],
"
_id
"
,
"
first createIndex first argument
"
);
equal
(
context
.
spy_create_index
.
firstCall
.
args
[
1
],
"
_id
"
,
"
first createIndex second argument
"
);
deepEqual
(
context
.
spy_create_index
.
firstCall
.
args
[
2
],
{
unique
:
true
},
"
first createIndex third argument
"
);
equal
(
context
.
spy_create_index
.
secondCall
.
args
[
0
],
"
_id
"
,
"
second createIndex first argument
"
);
equal
(
context
.
spy_create_index
.
secondCall
.
args
[
1
],
"
_id
"
,
"
second createIndex second argument
"
);
deepEqual
(
context
.
spy_create_index
.
secondCall
.
args
[
2
],
{
unique
:
false
},
"
second createIndex third argument
"
);
equal
(
context
.
spy_create_index
.
thirdCall
.
args
[
0
],
"
_id_attachment
"
,
"
third createIndex first argument
"
);
deepEqual
(
context
.
spy_create_index
.
thirdCall
.
args
[
1
],
[
"
_id
"
,
"
_attachment
"
],
"
third createIndex second argument
"
);
deepEqual
(
context
.
spy_create_index
.
thirdCall
.
args
[
2
],
{
unique
:
false
},
"
third createIndex third argument
"
);
equal
(
context
.
spy_create_index
.
getCall
(
3
).
args
[
0
],
"
_id
"
,
"
fourth createIndex first argument
"
);
equal
(
context
.
spy_create_index
.
getCall
(
3
).
args
[
1
],
"
_id
"
,
"
fourth createIndex second argument
"
);
deepEqual
(
context
.
spy_create_index
.
getCall
(
3
).
args
[
2
],
{
unique
:
false
},
"
fourth createIndex third argument
"
);
ok
(
context
.
spy_transaction
.
calledOnce
,
"
transaction count
"
+
context
.
spy_transaction
.
callCount
);
deepEqual
(
context
.
spy_transaction
.
firstCall
.
args
[
0
],
[
"
metadata
"
],
"
transaction first argument
"
);
equal
(
context
.
spy_transaction
.
firstCall
.
args
[
1
],
"
readonly
"
,
"
transaction second argument
"
);
ok
(
context
.
spy_store
.
calledOnce
,
"
store count
"
+
context
.
spy_store
.
callCount
);
deepEqual
(
context
.
spy_store
.
firstCall
.
args
[
0
],
"
metadata
"
,
"
store first argument
"
);
ok
(
context
.
spy_index
.
calledOnce
,
"
index count
"
+
context
.
spy_index
.
callCount
);
deepEqual
(
context
.
spy_index
.
firstCall
.
args
[
0
],
"
_id
"
,
"
index first argument
"
);
equal
(
context
.
spy_key_cursor
.
callCount
,
0
,
"
key_cursor count
"
+
context
.
spy_key_cursor
.
callCount
);
ok
(
context
.
spy_cursor
.
calledOnce
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -259,6 +364,43 @@
});
});
test
(
"
handle include_docs
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
1
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
return
RSVP
.
all
([
context
.
jio
.
put
(
"
2
"
,
{
"
title
"
:
"
title2
"
}),
context
.
jio
.
put
(
"
1
"
,
{
"
title
"
:
"
title1
"
})
]);
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
include_docs
:
true
});
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[{
"
id
"
:
"
1
"
,
"
value
"
:
{
"
title
"
:
"
title1
"
}
},
{
"
id
"
:
"
2
"
,
"
value
"
:
{
"
title
"
:
"
title2
"
}
}],
"
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