[IndexedDB] JSON schema specification (#64)

IndexedDB indexes are defined procedurally during database opening sequence on upgradeneeded event. Creating and deleting index requires a lot of boilerplate code and needed to compare with existing indexes. Instead of defining index in procedural, it is easier to defined indexes in JSON in database connection and let underlying database to do the job. 

For example 


    var schema = {
      version: 1, // optional,
      stores: [{
        name: 'author',
        keyPath: 'email',
        autoIncrement: false,
        indexes: [
          {
            name: 'born',
            keyPath: 'born',
            unique: false,
            multiEntry: false
          }
        ]
      }]
    };
  
    indexedDB.openFrom(schema).then(function (db) {
    }, function (e) {
    });

If version is not specified, version will be increment as necessary. Additionally, in this case, database connection will be reconnect for new version on the event of version change as illustrated in the following code snippet. This will solved a lot of pain point.

    db.onversionchange = function(e) {
      db.close();
      indexedDB.open(db.name).onsuccess = function(newDb) {
        db = newDb;
      }
    };






---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/IndexedDB/issues/64

Received on Friday, 12 February 2016 07:24:58 UTC