JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Include dexie.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dexie/2.0.1/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";}
</script>
CSS
textarea#log
{
width: 100%;
height: 1000px;
}
JavaScript
//
// Define database
//
var db = new Dexie("MyExampleDB");
db.version(1).stores({
example: 'key'
});
log ("Using Dexie v" + Dexie.semVer);
//
// Query Database
//
db.open().then(function(){
return db.example.add({key:"one",name:'name of one'});
}).then(function(){
return db.example.add({key:"two",name:'name of two'});
}).then(function(){
return db.example.toArray();
}).then(function(friends){
log("Found friends: " + JSON.stringify(friends, null, 2));
//Deleting!!!
return db.example.where('key').equals('one').delete();
}).then(function(){
return db.example.toArray();
}).then(function(examples){
log("-------------------------------------");
log("After Delete : " + JSON.stringify(examples, 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 (function (e) {
log (e);
});