@cyra/junkshop v1.0.4
Junkshop
Fuck databases. Sometimes you just want to persist some data on disk.\ Junkshop lets you persist anything that's json-serialisable (plus binary data) and search and manipulate it very similar to how you would manipulate a JavaScript object in memory, but without having to pull everything into memory to do it. It's a bit like using MongoDB with only a single document in a single collection. There are no collections and no documents here - everything is nested under one root "map". Junkshop is slow when compared to a proper database.
Basic usage
Install with npm:
npm install @cyra/junkshop
Enter the junkshop:
const junkshop = require('@cyra/junkshop')
const root = junkshop.enter(__dirname + '/db.db')
If no file exists at the specified path, a new sqlite database is initialised with the required schema.
The value returned by enter
is a JunkMap
Set a value on a key:
await root.set('map', { x: 0, y: 1, list: ['string 1', 'string 2'] })
Obtain a value:
console.log(await root.get('map', 'list', 0)) // 'string 1'
const arr = await root.get('map', 'list')
console.log(await arr.get(1)) // 'string 2'
get
directly resolves to a regular Javascript value if the specified path points to a number, string, boolean, null or binary data,
and resolves to a JunkMap
or JunkList
instance if it points to a collection.
Check the type of a value:
let isCollection = junkshop.isJunkCollection(arr) // true
let isMap = junkshop.isJunkMap(arr) // false
let isList = junkshop.isJunkList(arr) // true
Collect a collection:
console.log(await arr.collect()) // ['string 1', 'string 2']
Add an item to a list:
await arr.push('string 3')
Kill all workers:
root.workers.killAll()
Advanced usage
Might write proper documentation at some point idk