IndexedDB – Dexie JS : Dynamically create stores

I’m working with indexedDB for local data storage, with Dexie.js which is pretty nice as a wrapper, especially because of the advanced queries.
Actually, I would like to create to create several datastore by script, which seem complicated.
To create a new store, you would do something like :

    Doctors: "++" + strFields

if I do something like Dortors = “Hospital”, it still creates the store with a name “Doctors”.
Is there a way to do this?
Did anybody faced the same problem?

  • indexedDb backup in the cloud
  • Optimizing: Get specific Value(and not more) from IndexedDB
  • YDN-DB - How to update a record by id?
  • Processing a large (12K+ rows) array in JavaScript
  • Chrome devtools extension for IndexedDB
  • Most efficient way to populate/distribute indexedDB [datastore] with 350000 records
  • The mysterious case of disappearing blobs in Chrome (in IndexedDB)
  • IndexedDB getAll in non-Firefox browsers
  • How long can the server connection be persisted in db.js?
  • createObjectURL blob url not secure in Firefox
  • Performance issues with IndexedDB storing 250kB/s streaming data
  • An efficient way of removing objects from an indexedDB object store that are missing a property
  • One Solution collect form web for “IndexedDB – Dexie JS : Dynamically create stores”

    Let’s say you want three object stores “Doctors”, “Patients” and “Hospitals”, you would write something like:

    var db = new Dexie ("your-database-name");
        Doctors: "++id,name",
        Patients: "ssn",
        Hospitals: "++id,city"

    Note that you only have to specify the primary key and the required indexes. Primary key can optionally be auto-incremented (“++” prefixed). You could add as many properties to your objects as you wish without having to specify each one in the index list.

    db.Doctors.add({name: "Phil", shoeSize: 83});
    db.Patients.add({ssn: "721-07-446", name: "Randle Patrick McMurphy"});
    db.Hospitals.add({name: "Johns Hopkins Hospital", city: "Baltimore"});

    And to query different stores:

    db.Doctors.where('name').startsWithIgnoreCase("ph").each(function (doctor) {
        alert ("Found doctor: " +;
    db.Hospitals.where('city').anyOf("Baltimore", "NYC").toArray(function (hospitals) {
       alert ("Found hospitals: " + JSON.stringify(hospitals, null, 4));