Permalink
Browse files

initial

  • Loading branch information...
0 parents commit 5ea77022da50ce86e472340806f4a7b8f38893d7 @Raynos committed Nov 24, 2012
Showing with 139 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +19 −0 LICENCE
  3. +55 −0 README.md
  4. +29 −0 index.js
  5. +33 −0 package.json
@@ -0,0 +1,3 @@
+node_modules
+*.log
+*.err
19 LICENCE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,55 @@
+# level-livefeed
+
+Live query a range in leveldb
+
+## Example
+
+You query a range in the database. It will load the range from
+ disk and then also add on anything else you put or del from
+ it.
+
+It's basically a never ending feed like `tail -f`
+
+```js
+var livefeed = require("level-livefeed")
+ , level = require("levelidb")
+
+ , db = level("/tmp/db")
+
+var stream = livefeed(db, { start: "foo:", end: "foo;" })
+/* stream
+
+ { type: "put", key: keyFromDisk1, value: valueFromDisk1 }
+ { type: "put", key: keyFromDisk2, value: valueFromDisk2 }
+
+*/
+
+db.put("some key", "some value")
+/* stream
+ { type: "put", key: "some key", value: "some value" }
+*/
+
+db.del("die")
+/* stream
+ { type: "del", key: "die" }
+*/
+
+db.batch([
+ { type: "put", key: "one", value: "two" }
+ , { type: "del", key: "two" }
+])
+/* stream
+ { type: "put", key: "one", value: "two" }
+ , { type: "del", key: "two" }
+*/
+```
+
+## Installation
+
+`npm install level-livefeed`
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
@@ -0,0 +1,29 @@
+var ReadStream = require("read-stream")
+ , WriteStream = require("write-stream")
+
+module.exports = query
+
+function query(db, options) {
+ options = options || {}
+
+ var queue = ReadStream()
+ , stream = queue.stream
+ , start = options.start
+ , end = options.end
+
+ db.readStream(options)
+ .pipe(WriteStream(function write(chunk) {
+ chunk.type = "put"
+ queue.push(chunk)
+ }))
+
+ db.on("put", function put(key, value) {
+ queue.push({ type: "put", key: key, value: value })
+ })
+
+ db.on("del", function del(key) {
+ queue.push({ type: "del", key: key })
+ })
+
+ return stream
+}
@@ -0,0 +1,33 @@
+{
+ "name": "level-livefeed",
+ "version": "0.1.0",
+ "description": "Live query a range in leveldb",
+ "keywords": [],
+ "author": "Raynos <raynos2@gmail.com>",
+ "repository": "git://github.com/Raynos/level-livefeed.git",
+ "main": "index",
+ "homepage": "https://github.com/Raynos/level-livefeed",
+ "contributors": [
+ {
+ "name": "Jake Verbaten"
+ }
+ ],
+ "bugs": {
+ "url": "https://github.com/Raynos/level-livefeed/issues",
+ "email": "raynos2@gmail.com"
+ },
+ "dependencies": {
+ },
+ "devDependencies": {
+ "tap": "~0.3.1"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://github.com/Raynos/level-livefeed/raw/master/LICENSE"
+ }
+ ],
+ "scripts": {
+ "test": "tap --stderr --tap ./test"
+ }
+}

0 comments on commit 5ea7702

Please sign in to comment.