Skip to content

Retrieving data

Auguste Rame edited this page Oct 8, 2019 · 2 revisions

Data in streamlet can be accessed via the following commands: Retrieving

db.get(n)

let db = new streamlet(path.join(__dirname, 'db.sl'))

async () => {
  await db.init()
  db.get(0) // {item: 'foo', number: 1}
}

Will Get the nth non deleted item in the database

db.find(fn)

let db = new streamlet(path.join(__dirname, 'db.sl'))

async () => {
  await db.init()
  await db.find(i => {return i.name === 'bar'?i:undefined}) // {item: 'bar', number: 2}
}

db.find will return all items which can be iterated over in a function

db.findById(id)

let db = new streamlet(path.join(__dirname, 'db.sl'))

async () => {
  await db.init()
  await db.findById(`hFkEXrkuRyGQAf8t7vzshw/0000000000`) // {item: 'foo', number: 1}
}

This will find an item by its auto assigned _id

db.findIndex(fn)

???

db.findIndexes(fn)

???

Clone this wiki locally