-
Notifications
You must be signed in to change notification settings - Fork 86
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
Is it possible to create multiple dataStore in same db using angular-localForage? #51
Comments
Hmm it is the correct way to do it, and it should work, can I get your config ? |
app.config(['$localForageProvider', function($localForageProvider){
$localForageProvider.config({
driver : localforage.INDEXEDDB, // if you want to force a driver
name : 'dbName', // name of the database and prefix for your data, it is "lf" by default
version : 1.0, // version of the database, you shouldn't have to use this
storeName : 'tblGlobal', // name of the table
description : 'some description'
});
}]); |
Thanks, I'll check this tomorrow and I'll let you know. |
Thanks man :) |
Wow is it tomorrow already ? :P The problem is that when you create a new instance it uses the parameter "name" to keep track of the instances, and the name is also the name of the db. So if you define a new instance, you need to define a different name and it will create a new database... Thanks for the report, I'll let you know when it's fixed. |
Hi Olivier. Firstly, thanks for the great lib! I've also come across the use case highlighted by @bobsilon, the desire to use two separate dataStores, in particular with IndexedDB/WebSQL. In my own case, I'm putting together some simple diary functionality with the need to store entry meta data in one table, and the body content in another. For the moment I've made a couple of minor changes to the createInstance method as shown below, allowing the config property 'instanceName' to be used when provided, or to fall back to the 'name’ property as the key for the instances array. src/angular-localForage.js LocalForageInstance.prototype.createInstance = function createInstance(config) {
var instanceName = angular.isDefined(config.instanceName) ? config.instanceName : config.name;
if (angular.isObject(config)) { // create new instance
config = angular.extend({}, defaultConfig, config);
if (angular.isDefined(lfInstances[instanceName])) {
throw new Error('A localForage instance with the name ' + instanceName + ' is already defined.');
}
lfInstances[instanceName] = new LocalForageInstance(config);
return lfInstances[instanceName];
} else {
throw new Error('The parameter should be a config object.')
}
}; Simple enough, but currently only works when using the WebSQL driver. If you use IndexedDB the new instance will be created but the data won’t save as the following error is thrown.
When creating the second instance, I think because the same database name is being used the onupgradeneeded function in the IndexSQL driver isn’t fired and the second object store isn’t created. I’ve yet to get it working with IndexDB with the original suggestion made by @bobsilon, regarding incrementing the database version. Additionally, with localstorage the key doesn't seem to namespace the dataStore eg 'name\key' instead of 'name\dataStore\key', but I could just be missing something! It would be great if we could get this working. WebSQL works well for my current project platforms (Cordova for iOS / Android) but it would be great to get it working for IndexDB and LocalStorage. Cheers! |
Thanks for your investigation. |
ANy news on this ? |
I haven't had the time to work on it sorry, I had a busy beginning of 2015 :) |
Your error could be related to localForage/localForage#342 Relevant discussion also in localForage/localForage#367 |
Any News? |
Any updates on this ? |
No sorry I kinda let this project down :( |
If we pass storeName as an Array ? Though getItem will going to change. But is it a good way to do it ? |
Since localForage/localForage#342 seems now fixed and actually allows multiple stores/tables per database/instance - could this be adapted here as well? I wonder whether the approach by @nathanbrock above would just work now? Ok, going to try that .. |
hi, fixed the issue there. created a pull request |
Hi there. Is it possible to have multiple dataStore in IndexedDB using angular-localForage?
I tried this:
but it triggered an error which says:
I've read this Question before but, is the only way is working with Raw IndexedDB? Or I missed something in my code? Any Idea?
The text was updated successfully, but these errors were encountered: