Chapter 7: initial samples

This commit is contained in:
Beth Griggs
2020-05-16 14:33:26 +01:00
parent bcf782f7dc
commit adb2130b38
140 changed files with 1777 additions and 1960 deletions
+26
View File
@@ -0,0 +1,26 @@
const levelup = require('levelup')
const memdown = require('memdown')
const db = levelup(memdown('./data'))
const task = process.argv[2]
if (!task) {
listTasks()
} else {
addTask()
}
function addTask() {
const key = `Task: ${Math.random().toString(32).replace('.', '')}`
db.put(key, task, (err) => {
if (err) throw err
listTasks()
})
}
function listTasks() {
db.createReadStream().on('data', (data) => {
console.log(data.key.toString(), '=', data.value.toString())
})
}