-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows multiple object stores per database #69
Conversation
Ok, this now contains a fix for IE11. Because IE11 doesn't allow multiple connections to the same database, the script needs to explicitly close the first open connection before reopening to upgrade. IE11 test script: <!DOCTYPE html>
<html>
<head>
<script src="//cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script>window.exports = {};</script>
<script src="/idb-keyval-cjs-compat.min.js"></script>
</head>
<body>
<div id="main"></div>
<script>
var Store = window.exports.MultiStore;
var set = window.exports.set;
var get = window.exports.get;
var databaseName = "__test_multistore";
//indexedDB.deleteDatabase( databaseName );
var storeName = "__test_" + Date.now();
console.log( "Test object store:", storeName, "( in database", databaseName, ")" );
var store = new Store( databaseName, storeName );
var db, stores = [];
store._dbp.then( function( promised ) {
db = promised;
console.log( "Database version", db.version );
for(var i = 0; i < db.objectStoreNames.length; i++ ) stores.push( db.objectStoreNames[ i ] );
console.log( "Object stores", stores );
} ).then( function() {
console.log( "Set and get values from store" );
return set( "thanks", "fish", store );
} ).then( function() {
return get( "thanks", store );
} ).then( function( actual ) {
var expected = "fish";
console.log( "Expected", expected );
console.log( "Actual", actual );
if ( actual !== expected ) throw new Error( "Failed to set and retrieve value" );
} ).then( function() {
if ( stores.length === 0 )
throw new Error( "No store was created!" );
else if ( stores.length === 1 )
console.warn( "This test is not passed until you run it at least twice (by reloading)" );
else
console.log( "SUCCESS - the database was accessed with new object stores" );
} );
</script>
</body>
</html> |
@jakearchibald N.B. this fix does not change the fact that with IE11 you'll have to close the connection to one object store before opening a connection to another within the same database, but I think these two issues should be handled separately. |
Updated IE11 test above to use |
I'm subscribing to this, because this feature would be so very nice to have. :) |
@DonGissel, I ended up rewriting the same API as jake has here: https://github.com/goofballLogic/idb-lite if it's of any use |
Giving up on this being updated. |
For #31
If an object store is missing from a database, re-opens the database as the next version in order to allow upgrade to add the missing object store.