Search code examples
javascriptindexeddblawnchair

Lawnchair-IndexedDB doesn't support multiple records


I tried creating multiple records in indexed-db but it won't allow me, example, nike and adidas objectStores

var nike = Lawnchair({adapter:'indexed-db', name:'stores', record:'nike'},function(e){
    console.log("nike store open");
    this.save({id:1}, function(data){
        console.log('nike data: ', data);
    });
});

var adidas = Lawnchair({adapter:'indexed-db', name:'stores', record:'adidas'},function(e){
    console.log("adidas store open");
    this.save({id:1}, function(data){
        console.log('adidas data: ', data);
    });
});

I think this is how to create multiple records in indexed-db. It actually happens on request.onupgradeneeded. See code below.

// Handle datastore upgrades.
request.onupgradeneeded = function(e) {
    var db = e.target.result;

    var nike = db.createObjectStore('nike');
    var adidas = db.createObjectStore('adidas');
};

If I can't create an adidas record this is actually the error that is thrown when accessing it.

[Exception... "The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened." code: "8" ...]

Solution

  • Lawnchair is designed for schemaless use case. Use separate database for each Lawnchair instance.

    If you really need multiple tables in an database, you other libraries, like my own, ydn-db.