Skip to content

Commit

Permalink
Merge 04df5a4 into 37e2f8d
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Oct 15, 2014
2 parents 37e2f8d + 04df5a4 commit c188972
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 76 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,9 @@ LevelDB with [SubLevel](http://npm.im/level-sublevel):
```javascript
var levelup = require("level");
var sublevel = require("level-sublevel");
var levelWriteStream = require("level-writestream");
var levelgraph = require("levelgraph");
var db = sublevel(levelWriteStream(levelup("yourdb")));
var graph = levelgraph(db.sublevel('yourGraph'));
var db = sublevel(levelup("yourdb"));
var graph = levelgraph(db.sublevel('graph'));
```

## Browserify
Expand Down Expand Up @@ -630,7 +629,7 @@ href="https://github.com/jez0990">GitHub/jez0990</a></td></tr>

## LICENSE - "MIT License"

Copyright (c) 2013 Matteo Collina (http://matteocollina.com) and LevelGraph Contributors
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
24 changes: 24 additions & 0 deletions lib/filterstream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var Transform = require('readable-stream').Transform;

Expand Down
24 changes: 24 additions & 0 deletions lib/getdb-browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var Leveljs = require('level-js');
module.exports = function(l) { return new Leveljs(l); };
26 changes: 26 additions & 0 deletions lib/getdb.js
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/


module.exports = require('leveldown');
24 changes: 24 additions & 0 deletions lib/joinstream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var Transform = require('readable-stream').Transform
, Variable = require('./variable')
Expand Down
44 changes: 37 additions & 7 deletions lib/levelgraph.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var filterStream = require('./filterstream')
, materializer = require('./materializerstream')
Expand All @@ -8,7 +32,7 @@ var filterStream = require('./filterstream')
, queryplanner = require('./queryplanner')
, PassThrough = require('readable-stream').PassThrough
, WriteStream = require('./writestream')
, levelWriteStream = require('level-writestream')
, levelWriteStream = require('level-write-stream')
, levelup = require('levelup')
, Leveljs
, searchStream
Expand Down Expand Up @@ -56,12 +80,8 @@ module.exports = function levelgraph(leveldb, options, readyCallback) {

}

utilities.patchApproximateSize(leveldb);

// it may be an empty object if we are on browserify.
// we are not patching it up if a sublevel is passed in.
if (typeof levelWriteStream === 'function' && leveldb.parent) {
levelWriteStream(leveldb);
if (!leveldb.createWriteStream) {
leveldb.createWriteStream = levelWriteStream(leveldb);
}

db = {
Expand Down Expand Up @@ -93,6 +113,9 @@ module.exports = function levelgraph(leveldb, options, readyCallback) {
, v: Variable
, searchStream: searchStream(leveldb, options)
, search: utilities.wrapCallback('searchStream')
, isOpen: function() {
return leveldb.isOpen();
}
, nav: function(start) {
return new Navigator({ start: start, db: this });
}
Expand All @@ -109,6 +132,13 @@ module.exports = function levelgraph(leveldb, options, readyCallback) {
return db.search(a, b, c);
};

db.approximateSize = function(pattern, callback) {
var query = utilities.createQuery(utilities.queryMask(pattern));
leveldb.db.approximateSize(query.start, query.end, function (error, size) {
callback(error, error ? null : size >> 8);
});
};

if (callTheCallback && readyCallback) {
process.nextTick(readyCallback.bind(null, null, db));
}
Expand Down
24 changes: 24 additions & 0 deletions lib/materializerstream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var Transform = require('readable-stream').Transform
, materializer = require('./utilities').materializer;
Expand Down
25 changes: 25 additions & 0 deletions lib/navigator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var Variable = require('./variable')
, Transform = require('readable-stream').Transform
, CallbackStream = require('callback-stream')
Expand Down
24 changes: 24 additions & 0 deletions lib/queryplanner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var utilities = require('./utilities')
, queryMask = utilities.queryMask
Expand Down
26 changes: 25 additions & 1 deletion lib/sortjoinstream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var Transform = require('readable-stream').Transform
, Variable = require('./variable')
Expand Down Expand Up @@ -90,7 +114,7 @@ SortJoinStream.prototype._start = function() {
that.emit('error', err);
});

this._readStream.on('end', function() {
this._readStream.on('close', function() {
that._readStream = null;
if (!that._previousTriple) {
that._execLastDone();
Expand Down
57 changes: 24 additions & 33 deletions lib/utilities.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
Copyright (c) 2013-2014 Matteo Collina and LevelGraph Contributors
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.
*/

var CallbackStream = require('callback-stream')
, Variable = require('./variable')
Expand Down Expand Up @@ -240,36 +264,3 @@ function matcher(pattern) {
}

module.exports.matcher = matcher;

function patchApproximateSize(leveldb) {
// we need to be sublevel-aware
var db = leveldb.db || leveldb._root.db;

// monkey patching _approximateSize
// see https://github.com/maxogden/level.js/pull/21
function doPatch(db) {
if (db.constructor.name === 'Level') {
// we are in Level-js
db._approximateSize = function(a, b, callback) {
var err = new Error('Not implemented');
if (callback) {
return callback(err);
}

throw err;
};
}
}

if (db.constructor.name === 'DeferredLevelDOWN') {
db.setDb = function() {
doPatch(arguments[0]);
var result = db.constructor.prototype.setDb.apply(db, arguments);
return result;
};
} else {
doPatch(db);
}
}

module.exports.patchApproximateSize = patchApproximateSize;
Loading

0 comments on commit c188972

Please sign in to comment.