Coder Social home page Coder Social logo

Comments (16)

ocombe avatar ocombe commented on August 10, 2024

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.

bobsilon avatar bobsilon commented on August 10, 2024
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.

ocombe avatar ocombe commented on August 10, 2024

Thanks, I'll check this tomorrow and I'll let you know.

from angular-localforage.

bobsilon avatar bobsilon commented on August 10, 2024

Thanks man :)

from angular-localforage.

ocombe avatar ocombe commented on August 10, 2024

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.

nathanbrock avatar nathanbrock commented on August 10, 2024

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.

ocombe avatar ocombe commented on August 10, 2024

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.

saniyusuf avatar saniyusuf commented on August 10, 2024

ANy news on this ?

from angular-localforage.

ocombe avatar ocombe commented on August 10, 2024

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.

psalaets avatar psalaets commented on August 10, 2024

@nathanbrock

Your error could be related to localForage/localForage#342

Relevant discussion also in localForage/localForage#367

from angular-localforage.

saniyusuf avatar saniyusuf commented on August 10, 2024

Any News?

from angular-localforage.

shardulP avatar shardulP commented on August 10, 2024

Any updates on this ?

from angular-localforage.

ocombe avatar ocombe commented on August 10, 2024

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.

shardulP avatar shardulP commented on August 10, 2024

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.

ansorg avatar ansorg commented on August 10, 2024

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.

hozkok avatar hozkok commented on August 10, 2024

hi, fixed the issue there.

created a pull request

#119

from angular-localforage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.