Comments (16)
Hmm it is the correct way to do it, and it should work, can I get your config ?
If it's a bug I need to fix this.
from angular-localforage.
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'
});
}]);
from angular-localforage.
Thanks, I'll check this tomorrow and I'll let you know.
from angular-localforage.
Thanks man :)
from angular-localforage.
Wow is it tomorrow already ? :P
Sorry I forgot to follow up on this :(
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...
I really did not think to this use case when I implemented the instances. I need to change the way I store instances to make this work...
Thanks for the report, I'll let you know when it's fixed.
from angular-localforage.
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.
"Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found."
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!
from angular-localforage.
Thanks for your investigation.
I'll probably have to do a breaking change to fix this problem. I'm not sure that instances are really used by a lot of people right now, so this shouldn't be too serious.
I'll let you know when I have the time to work on this (I don't have a lot of free time this month).
from angular-localforage.
ANy news on this ?
from angular-localforage.
I haven't had the time to work on it sorry, I had a busy beginning of 2015 :)
It's still on my todo list though.
from angular-localforage.
Your error could be related to localForage/localForage#342
Relevant discussion also in localForage/localForage#367
from angular-localforage.
Any News?
from angular-localforage.
Any updates on this ?
from angular-localforage.
No sorry I kinda let this project down :(
If you know anyone interested in taking over that would be cool because I don't have much time these days.
from angular-localforage.
If we pass storeName as an Array ? Though getItem will going to change. But is it a good way to do it ?
from angular-localforage.
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 ..
from angular-localforage.
hi, fixed the issue there.
created a pull request
from angular-localforage.
Related Issues (20)
- Versioning DB HOT 3
- Bump localForage to 1.4.2
- Clean up and update depedencies HOT 1
- Support passing back an object on multi-getItem lookup
- import/require should return module name HOT 6
- question: angular-localForage support indexedDB, webSQL, localstorage, but i don't know which one it is the default choice HOT 1
- Q: Is there the maximun about angular-localForage HOT 1
- does bind() a two way binding? HOT 4
- Change dependencies from dist to source? HOT 4
- Using directive and deleting value keeps 3 characters in the field HOT 5
- Storing huge object freeze my app HOT 9
- Use getItem instead of iterate for small getItem array lookups HOT 2
- Facebook In-App Browser HOT 6
- $$hashKey is now being saved on setitem HOT 8
- i get this error when i'm tring to use electron app with angular-localforage HOT 5
- Correct usage with webpack HOT 3
- iOS safari support indexedDB HOT 6
- Support for AngularJs 1.6! HOT 4
- Nested Promises do not work HOT 3
- setItem call does not return an angular promise but an ES6 promise HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-localforage.