Dexie.js (open existing DB)

Fiddle with Dexie.js from Dexie wiki sample

by David Fahlander

HTML

<!-- Include dexie.js -->
<script src="https://npmcdn.com/dexie/dist/dexie.js"></script>

<!-- Some HTML for the log window -->
<a href="http://dexie.org/docs/API-Reference" target="_new">Dexie API Reference (new tab)</a>

<h3>Log</h3>
<textarea id="log"></textarea>

<!-- Just a simple log function... --> 
<script>
  function log(txt) {document.getElementById('log').value+=txt+"\n";}

  // Check that browser supports generator functions:
  try{eval("(function* (){})");}catch(e){
    log("This browser doesn't support generator functions. Must use a recent version of Chrome, Opera, Firefox or Edge.");
  }
</script>

CSS

textarea#log {
  width: 100%;
  height: 1000px;
}

JavaScript

new Dexie('MyDatabase').open().then(function (db) {
    log ("Found database: " + db.name);
    log ("Database version: " + db.verno);
    db.tables.forEach(function (table) {
        log ("Found table: " + table.name);
        log ("Table Schema: " +
            JSON.stringify(table.schema, null, 4));
    });
}).catch('NoSuchDatabaseError', function(e) {
    // Database with that name did not exist
    log ("Database not found");
}).catch(function (e) {
    log ("Oh uh: " + e);
});