Simple Storage

Read and Write Using the db Helper

The db helpers reads/writes to json files in the ~/.kenv/db directory. It's meant as a simple wrapper around common json operations.

// Menu: Database Read/Write Example
// Description: Add/remove items from a list of fruit
let fruitDb = await db(["apple", "banana", "orange"])
// This will keep prompting until you hit Escape
while (true) {
let fruitToAdd = await arg(
{
placeholder: "Add a fruit",
//allows to submit input not in the list
strict: false,
},
fruitDb.items
)
fruitDb.items.push(fruitToAdd)
await fruitDb.write()
let fruitToDelete = await arg(
"Delete a fruit",
fruitDb.items
)
fruitDb.items = fruitDb.items.filter(
fruit => fruit !== fruitToDelete
)
await fruitDb.write()
}

Open db-store in Script Kit

Discuss Post