Dexie.js

Fiddle with Dexie.js

by Terrance Smith

HTML

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

<!-- Some HTML for the log window -->
<a href="https://github.com/dfahlander/Dexie.js/wiki/API%20Reference" target="_new">Dexie API Reference (new tab)</a>
<div style="float:right">Check out this
  <a href="https://jsfiddle.net/dfahlander/b7axqyjw/" target="yf">
    yield fiddle </a> also!
</div>
<h3>Log</h3>
<textarea id="log"></textarea>

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

</script>

CSS

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

JavaScript

//
// Define database
//
/*
var db = new Dexie("MyFriendDB");
db.version(1).stores({
	friends: '++id,name,age'
});
log ("Using Dexie v" + Dexie.semVer);
//
// Query Database
//
db.open().then(function(){

	return db.friends.add({name: "Foo", age: 42});
  
}).then(function(){

	return db.friends
		.where('age')
		.between(40,65)
		.toArray();

}).then(function(friends){

	log("Found friends: " + JSON.stringify(friends, null, 2));
  
}).then(function(){
	return db.delete(); // So you can experiment again and again...
}).catch (Dexie.MissingAPIError, function (e) {
	log ("Couldn't find indexedDB API");
}).catch ('SecurityError', function(e) {
  log ("SeurityError - This browser doesn't like fiddling with indexedDB.");
  log ("Go run some samples instead at: https://github.com/dfahlander/Dexie.js/wiki/Samples");
}).catch (function (e) {
	log (e);
});
*/

log("Dexie = "+Dexie);
log("HERE");
Dexie.getDatabaseNames(function(databases) {
  log("databases.length = " + databases.length);
  for (var i = 0; i < databases.length; ++i) {
    log(databases[i]);
  }
});