2

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" ...]
paolooo
  • 4,133
  • 2
  • 18
  • 33

2 Answers2

1

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.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
  • Hi Kyaw Tun, I've downloaded your library but I'm having problem compiling it. It generate|-ydn.db-jquery-0.7.7.js | | |-zss-ydn.db-conn.js | | |-zss-ydn.db-core-db.js | | |-zss-ydn.db-core-idb.js | | |-zss-ydn.db-core.js | | |-zss-ydn.db-crud-db.js | | |-zss-ydn.db-crud-idb.js | | |-zss-ydn.db-crud-simple.js | | |-zss-ydn.db-crud-websql.js | | |-zss-ydn.db-crud.js | | |-zss-ydn.db-dev.js | | |-zss-ydn.db-dev.js.map | | |-zss-ydn.db-jquery.js | | |-zss-ydn.db-raw.js | | `-zss-ydn.db.js – paolooo Aug 03 '13 at 09:19
  • Hi Kyawn, can you please explain what are the difference between those *.js? :) Thanks. This is a great library. Also, is there any option for me to choose what storage should I use? Example, let's say I want to use websql instead of indexed-db. My chrome supports websql and indexed-db. :) – paolooo Aug 03 '13 at 12:09
  • 1
    These are binary distributions. You use any one, depending on what feature you want. To change storage mechanisms, change `mechanisms` in the options. For more detail see, api doc http://dev.yathit.com/api-reference/ydn-db/storage.html – Kyaw Tun Aug 04 '13 at 04:56
  • Awesome! Thank you Kyaw. Your ydn-db library is perfect :) – paolooo Aug 05 '13 at 18:07
  • hi, kyawn tun, I just want to confirm if ydn-db supports in mobile / phonegap? – paolooo Aug 14 '13 at 03:07
  • Yes. Check out android demo app. – Kyaw Tun Aug 14 '13 at 03:13
1

Found a way to fix it. I've added a patch by adding a records property on option object. See {adapter..., records:[...]} below.

<script>

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


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

</script>

See my pull request here: https://github.com/brianleroux/lawnchair/pull/175

paolooo
  • 4,133
  • 2
  • 18
  • 33