Published
Edited
Feb 7, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db = new loki('sandbox.db')
Insert cell
Insert cell
mutable te_items = db.addCollection('items');
Insert cell
Insert cell
Insert cell
Insert cell
add_form_to_database = html`<button style="background-color:#EBA486;color:#0E0F1A" onclick=${() => {
mutable te_items.insert(items.value);
mutable te_items = mutable te_items; // trigger downstream cells
console.log(items.value)
}}>Add above to the ${db.filename}</button>`
Insert cell
Add_One_entery_to_the_database = html`<button style="background-color:#EBA486;color:#0E0F1A" onclick=${() => {
mutable te_items.insert({ name : 'Bob', owner: 'MON', maker: 'burgers' });
mutable te_items = mutable te_items; // trigger downstream cells
}}>Add One entery to the database ${db.filename}</button>`
Insert cell
Insert cell
viewof addData = html`<button style="background-color:#EBA486;color:#0E0F1A" >Add Four enteries to the data ${db.filename}</button>`
Insert cell
// Insert some documents to the collection
// needs to test that these are present
add_data = {
addData; // run again when the button is clicked
mutable te_items.insert({ name : 'mjolnir', owner: 'thor', maker: 'dwarves' });
mutable te_items.insert({ name : 'gungnir', owner: 'odin', maker: 'elves' });
mutable te_items.insert({ name : 'tyrfing', owner: 'Svafrlami', maker: 'dwarves' });
mutable te_items.insert({ name : 'draupnir', owner: 'odin', maker: 'elves' });
mutable te_items = mutable te_items; // trigger downstream cells
}
Insert cell
te_items.data
Insert cell
Insert cell
where_results = {
wheres_bob;
return te_items.where(function(obj) {
return obj.name === "Bob";
});
}
Insert cell
viewof wheres_bob = html`<button style="background-color:#EBA486;color:#0E0F1A" >Lets see if BoB is in the database ${db.filename}</button>`
Insert cell
Insert cell
viewof doThis = html`<button style="background-color:#EBA486;color:#0E0F1A">Find and update</button>`
Insert cell
find = {
add_data; // depends on add_data inserting tyrfing
doThis;
var tyrfing = mutable te_items.findOne({'name': 'tyrfing'});
tyrfing.owner = 'todd';
mutable te_items.update(tyrfing);
mutable te_items = mutable te_items;
}
Insert cell
Insert cell
loki = require('lokijs@1.5.11/src/lokijs.js').catch(() => window["loki"])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more