JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawcdn.githack.com/alexcorvi/tydb/1be514762334023764e960e54be0f2085f2887b9/dist/index.browser.js"></script>
<button onclick="add()">Add</button> <button onclick="deleteAll()">delete all</button>
<table id="table">
</table>
CSS
#table {
white-space: pre;
}
JavaScript
const table = document.getElementById("table");
const db = new tydb.Database({
ref: "abc",
persistence_adapter: tydb.IDB_Persistence_Adapter
});
function updateTable () {
table.innerHTML = '';
db.find({}).then(docs=>{
docs.forEach(doc=>{
table.innerHTML = table.innerHTML + `<tr> <td> ${JSON.stringify(doc, null, 4)} </td> </tr>`;
});
});
}
// update table every 1 s
setInterval(updateTable,1000);
function add() {
db.insert([{
age: Math.floor(Math.random() * (100 - 5 + 1)) + 5,
yearEmployed: Math.floor(Math.random() * (2020 - 2001 + 1)) + 2001
}])
}
function deleteAll() {
db.delete({filter: {}, multi: true});
}