abstract-nosql
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -1,78 +0,2 @@ | ||
/* Copyright (c) 2013 Rod Vagg, MIT License */ | ||
var inherits = require('util').inherits | ||
module.exports = require('abstract-object/Error') | ||
var kOk = 0 | ||
, kNotFound = 1 | ||
, kCorruption = 2 | ||
, kNotSupported = 3 | ||
, kInvalidArgument = 4 | ||
, kIOError = 5 | ||
, kNotOpened = 101 | ||
, kInvalidType = 102 | ||
, kInvalidFormat = 103 | ||
var errors = { | ||
"Ok": kOk | ||
, "NotFound": kNotFound | ||
, "Corruption": kCorruption | ||
, "NotSupported": kNotSupported | ||
, "InvalidArgument": kInvalidArgument | ||
, "IO": kIOError | ||
, "NotOpened": kNotOpened | ||
, "InvalidType": kInvalidType | ||
, "InvalidFormat": kInvalidFormat | ||
} | ||
function firstLower(s) { | ||
return s[0].toLowerCase()+s.substring(1) | ||
} | ||
function AbstractError(msg, errno) { | ||
Error.call(this, msg) | ||
this.code = errno | ||
this.message = msg | ||
if (Error.captureStackTrace) | ||
Error.captureStackTrace(this, arguments.callee) | ||
} | ||
inherits(AbstractError, Error) | ||
function NotImplementedError() { | ||
AbstractError.call(this, "NotImplemented", kNotSupported) | ||
} | ||
inherits(NotImplementedError, AbstractError) | ||
for (var k in errors) { | ||
AbstractError[k] = errors[k] | ||
//generate AbstractError.isNotFound(err) class methods: | ||
AbstractError["is"+k] = (function(i, aType) { | ||
return function(err) { | ||
return err.code === i || (err.code == null && err.message && err.message.substring(0, aType.length) === aType) | ||
} | ||
})(errors[k], k) | ||
//generate AbstractError.notFound() instance methods: | ||
AbstractError.prototype[firstLower(k)] = (function(aType) { | ||
return function() { | ||
return AbstractError[aType](this) | ||
} | ||
})("is"+k) | ||
if (errors[k]>0) { | ||
var Err = (function(i, aType){ | ||
return function(msg) { | ||
if (msg == null || msg == "") msg = aType | ||
AbstractError.call(this, msg, i) | ||
} | ||
})(errors[k], k) | ||
inherits(Err, AbstractError) | ||
//generate NotFoundError Classes | ||
module.exports[k+"Error"] = Err | ||
} | ||
} | ||
module.exports.AbstractError = AbstractError | ||
module.exports.NotImplementedError = NotImplementedError | ||
{ | ||
"name": "abstract-nosql", | ||
"description": "An abstract prototype for nosql database(LevelDOWN API)", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"contributors": [ | ||
@@ -35,2 +35,3 @@ "Riceball LEE <snowyu.lee@gmail.com> (https://github.com/snowyu)", | ||
"dependencies": { | ||
"abstract-object": "^1.1.0", | ||
"xtend": "~3.0.0" | ||
@@ -37,0 +38,0 @@ }, |
100
README.md
@@ -32,5 +32,5 @@ # Abstract NoSQL Database [![Build Status](https://secure.travis-ci.org/snowyu/node-abstract-nosql.png)](http://travis-ci.org/snowyu/node-abstract-nosql) | ||
## Changes | ||
## Changes(diference from abstract-leveldown) | ||
+ !TODO: Add the stream ability | ||
+ Add the AbstractError and error code supports. | ||
@@ -140,2 +140,28 @@ * DB constructor allows no location. | ||
//use it directly | ||
var db = new FakeLevelDOWN() | ||
//sync: | ||
db.put('foo', 'bar') | ||
var result = db.get('foo') | ||
//async: | ||
db.put('foo', 'bar', function (err) { | ||
if (err) throw err | ||
db.get('foo', function (err, value) { | ||
if (err) throw err | ||
console.log('Got foo =', value) | ||
db.isExists('foo', function(err, isExists){ | ||
if (err) throw err | ||
console.log('isExists foo =', isExists) | ||
}) | ||
}) | ||
}) | ||
//stream: | ||
db.readStream().on('data', function(data){ | ||
}) | ||
// now use it in LevelUP | ||
@@ -243,2 +269,51 @@ | ||
## Streamable | ||
Once implements the AbstractIterator.\_nextSync() or AbstractIterator.\_next(). | ||
the db should be the streamable. | ||
### AbstractLevelDOWN.createReadStream | ||
### AbstractLevelDOWN.readStream | ||
create a readable stream. | ||
* AbstractLevelDOWN.readStream([options]) | ||
* AbstractLevelDOWN.createReadStream | ||
__arguments__ | ||
* options: the optional options object | ||
* `'next'` *()*: the raw key data to ensure the readStream return keys is greater than the key. See `'last'` event. | ||
* note: this will affect the range[gt/gte or lt/lte(reverse)] options. | ||
* `'filter'` *(function)*: to filter data in the stream | ||
* function filter(key, value) if return: | ||
* 0(.FILTER_INCLUDED): include this item | ||
* 1(.FILTER_EXCLUDED): exclude | ||
* -1(.FILTER_STOPPED): stop stream. | ||
* note: the filter function argument 'key' and 'value' may be null, it is affected via keys and values of this options. | ||
* `'range'` *(string or array)*: the keys are in the give range as the following format: | ||
* string: | ||
* "[a, b]": from a to b. a,b included. this means {gte='a', lte = 'b'} | ||
* "(a, b]": from a to b. b included, a excluded. this means {gt='a', lte='b'} | ||
* "[, b)" from begining to b, begining included, b excluded. this means {lt='b'} | ||
* note: this will affect the gt/gte/lt/lte options. | ||
* array: the key list to get. eg, ['a', 'b', 'c'] | ||
* `'match'` *(string)*: use the minmatch to match the specified keys. | ||
* Note: It will affect the range[gt/gte or lt/lte(reverse)] options maybe. | ||
* `'limit'` *(number, default: `-1`)*: limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. | ||
__return__ | ||
* object: the read stream object | ||
#### Events | ||
the standard `'data'`, '`error'`, `'end'` and `'close'` events are emitted. | ||
the `'last'` event will be emitted when the last data arrived, the argument is the last raw key. | ||
if no more data the last key is `undefined`. | ||
## Extensible API | ||
@@ -254,2 +329,3 @@ | ||
### AbstractLevelDOWN#_getSync(key, options) | ||
### AbstractLevelDOWN#_isExistsSync(key, options) | ||
### AbstractLevelDOWN#_putSync(key, value, options) | ||
@@ -264,2 +340,3 @@ ### AbstractLevelDOWN#_delSync(key, options) | ||
### AbstractLevelDOWN#_get(key, options, callback) | ||
### AbstractLevelDOWN#_isExists(key, options, callback) | ||
### AbstractLevelDOWN#_put(key, value, options, callback) | ||
@@ -307,2 +384,16 @@ ### AbstractLevelDOWN#_del(key, options, callback) | ||
__arguments__ | ||
* options *(obeject)*: optional object with the following options: | ||
* `'gt'` (greater than), `'gte'` (greater than or equal) define the lower bound of the range to be streamed. Only records where the key is greater than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. | ||
* `'lt'` (less than), `'lte'` (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the records streamed will be the same. | ||
* `'reverse'` *(boolean, default: `false`)*: a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek. | ||
* `'keys'` *(boolean, default: `true`)*: whether contain keys. | ||
* `'values'` *(boolean, default: `true`)*: whether contain values. | ||
* `'limit'` *(number, default: `-1`)*: limit the number of results collected by this stream. This number represents a *maximum* number of results and may not be reached if you get to the end of the data first. A value of `-1` means there is no limit. When `reverse=true` the highest keys will be returned instead of the lowest keys. | ||
* `'fillCache'` *(boolean, default: `false`)*: wheather LevelDB's LRU-cache should be filled with data read. | ||
### AbstractIterator(db) | ||
@@ -319,4 +410,4 @@ | ||
* if any result: return a two elements of array | ||
* the first is the key | ||
* the second is the value | ||
* the first is the key, the first element could be null or undefined if options.keys is false | ||
* the second is the value, the second element could be null or undefined if options.values is false | ||
* or return false, if no any data yet. | ||
@@ -356,2 +447,3 @@ | ||
<table><tbody> | ||
<tr><th align="left">Riceball LEE</th><td><a href="https://github.com/snowyu">GitHub/snowyu</a></td><td> </td></tr> | ||
<tr><th align="left">Rod Vagg</th><td><a href="https://github.com/rvagg">GitHub/rvagg</a></td><td><a href="http://twitter.com/rvagg">Twitter/@rvagg</a></td></tr> | ||
@@ -358,0 +450,0 @@ <tr><th align="left">John Chesley</th><td><a href="https://github.com/chesles/">GitHub/chesles</a></td><td><a href="http://twitter.com/chesles">Twitter/@chesles</a></td></tr> |
142169
31
3280
464
2
+ Addedabstract-object@^1.1.0
+ Addedabstract-object@1.9.1(transitive)
+ Addedd@1.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedevents-ex@0.9.8(transitive)
+ Addedext@1.7.0(transitive)
+ Addedinherits-ex@1.0.9(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedutil-ex@0.2.9(transitive)
+ Addedxtend@4.0.2(transitive)