GithubHelp home page GithubHelp logo

kv's Introduction

kv-stream

super simple key-value store, intended for keeping appendable files.

works on the server, with files or redis and in the browser with localStorage.

on the server, it keeps the files in prefixed subdirectories, so that the directories do not get too large.

(see ls .git/objects/* for a similar example)

examples

###create an instance

kv(path/prefix/connectString, setup)

path is where to create/connect to the store.

setup is optional. setup is passed the stream created by put and get, may replace the stream passed to put/get by default, the stream is handled as newline seperated json.

//files
var kv = require('kv')('/tmp/kv')
//redis
var kv = require('kv/redis')('redis://password@localhost:6379/prefix')
//client
var kv = require('kv')('kv:') //this will be prefixed to keys when saving in localStorage.

put a stream

opts is optional. see fs.createWriteStream

stream.pipe(kv.put(key, opts))

kv.createWriteStream is a synonym for kv.put

get a stream

opts is optional. see fs.createReadStream

kv.get(key, opts).pipe(stream) 

kv.createReadStream is a synonym for kv.get

del a stream

kv.del(key, callback)

list of keys

kv.list().pipe(stream)

has

check if db has a key

  kv.has(key, function (err, stat) {
    //return the stat of the stream, if it exists.
  })

customization

to handle other types of streams than newline separated json, pass in a stream setup function to kv.

var rawKV = require('kv')(dir, function (stream, key) {
  return stream //just use raw streams, do not parse!
})

cli

there is also a cli tool!

npm install kv -g

echo hello | kv put hello --base /tmp/kv
kv get hello --base /tmp/k

kv's People

Contributors

dominictarr avatar juliangruber avatar tonistiigi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.