npm.io
2.0.1 • Published 7 years ago

akv

Licence
MIT
Version
2.0.1
Deps
2
Size
22 kB
Vulns
0
Weekly
0

akv

Build Status npm Version JS Standard

A simple key value store using single json file

Installation

$ npm install akv --save

Usage

'use strict'

const akv = require('akv')
const co = require('co')

co(function * () {
  let storage = akv('tmp/my-storage.json')
  // Set key value
  yield storage.set('foo', 'bar')

  // Get key value
  let foo = yield storage.get('foo')
  console.log(foo) // => bar
  // Delete by key
  yield storage.del('foo')
}).catch((err) => console.error(err))

Methods

Available methods

Signature Description
.touch() -> Promise Touch file
.set(key, value) -> Promise Set a value
.keys() -> Promise Get all keys
.get(key) -> Promise Get a value
.all() -> Promise Get all values
.del(key) -> Promise Delete a value
.destroy() -> Promise Delete all values

Tips

Commit to files

Normally, akv flushes data into files with some interval. But somethings you need to explicitly call commit changes.

let storage = akv('tmp/my-storage.json')
/* ... */
storage.commit() // Force to flush files

License

This software is released under the MIT License.

Keywords