<!-- 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]);
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.