Commit 2c9a21be authored by Aral Balkan's avatar Aral Balkan

Latest tests

parent 826a63ce
......@@ -11,6 +11,13 @@ if (isBrowser) {
const encode = require('encoding-down')
const levelup = require('levelup')
// Cannot test level-sublevel as it is broken with the latest versions of
// level. LevelDB on Node still feels like a minefield. Stopping here; I think
// I’ve persuaded myself to go with Dexie and handle any issues with
// IndexedDBShim if/when they arise.
// const sublevel = require('level-sublevel')
// Create/open database
const db = levelup(encode(leveldown('tasks'), {valueEncoding: 'json'}))
......@@ -40,6 +47,23 @@ async function start () {
// await Promise.all(insertPromises)
// displayDurationFor(`${numInserts} naïve inserts`)
// Batch insert index.
// Index is for the done flag and has two keys: 0 (not done), and 1 (done) with an array of keys on each.
// const doneIndex = db.sublevel('done')
// db.pre(async (change, add) => {
// // Add the key to either the 0 or the 1 key in the done flag index
// const doneValue = change.value.done
// let doneArray = db.get(doneValue)
// doneArray.push(change.key)
// add({
// key: doneValue,
// value: doneArray,
// type: 'put',
// prefix: doneIndex
// })
// })
// Batch inserts
let operations = []
for (let i = 0; i < numInserts; i++) {
......@@ -50,9 +74,6 @@ async function start () {
await db.batch(operations)
displayDurationFor(`${numInserts} batch inserts`)
// const value = await db.get('name', { asBuffer: false })
// console.log(value)
// Read stream
// resetTimer()
// db.createReadStream({asBuffer: false})
......@@ -65,9 +86,15 @@ async function start () {
// Single get
resetTimer()
const value = await db.get(2500)
const value1 = await db.get(2500)
displayDurationFor('Single get')
console.log(JSON.stringify(value))
console.log(value1)
// Get done items
// resetTimer()
// const value2 = await doneIndex.get(1)
// console.log(value2)
// displayDurationFor('Get done items.')
// Multiple gets
let promises = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment