Skip to content

Commit

Permalink
Merge branch 'boxxxie-master' into v0.7-wip
Browse files Browse the repository at this point in the history
Conflicts:
	lib/levelgraph.js
	package.json
	test/triple_store_spec.js
  • Loading branch information
mcollina committed Dec 23, 2013
2 parents bd57ace + fe20062 commit 6c12af3
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 20 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Expand Up @@ -2,6 +2,10 @@
History
======

## 0.6.12

* README update [#44](https://github.com/mcollina/levelgraph/pull/44).

## 0.6.11

* Fixed memory leak by upgrading to LevelUp 0.18 and LevelDown 0.10.
Expand Down
28 changes: 24 additions & 4 deletions README.md
Expand Up @@ -463,11 +463,27 @@ var db = levelgraph(levelup("yourdb", { db: factory }));

Follow the [Testling install instructions](https://github.com/substack/testling#install) and run `testling` in the levelgraph directory to run the test suite against a headless browser using level.js

## N3/Turtle/RDF support
## RDF support

__LevelGraph__ does not support loading and storing N3/turtle/RDF out of
the box, but the functionality is provided by
[LevelGraph-N3](https://github.com/mcollina/levelgraph-n3).
__LevelGraph__ does not support out of the box loading serialized RDF or storing it. Such functionality is provided by extensions:
* [LevelGraph-N3](https://github.com/mcollina/levelgraph-n3) - __N3/Turtle__
* [LevelGraph-JSONLD](https://github.com/mcollina/levelgraph-jsonld) - __JSON-LD__

## Extensions

You can use multiple extensions at the same time. Just check if one depends on another one
to nest them in correct order! *(LevelGraph-N3 and LevelGraph-JSONLD are
independent)*

```javascript
var lg = require('levelgraph');
var lgN3 = require('levelgraph-n3');
var lgJSONLD = require('levelgraph-jsonld');

var db = lgJSONLD(lgN3(lg("yourdb")));
// gives same result as
var db = lgN3(lgJSONLD(lg("yourdb")));
```

## TODO

Expand All @@ -485,6 +501,10 @@ Here are some ideas:
[#10](https://github.com/mcollina/levelgraph/issues/10)
* [ ] Live searches
[#3](https://github.com/mcollina/node-levelgraph/issues/3)
* Extensions
* [ ] RDFa
* [ ] RDF/XML
* [ ] Microdata

## Contributing

Expand Down
53 changes: 40 additions & 13 deletions lib/levelgraph.js
Expand Up @@ -20,32 +20,55 @@ var joinDefaults = {
solution: {}
};

module.exports = function levelgraph(leveldb, options) {
module.exports = function levelgraph(leveldb, options, readyCallback) {
function initDB(options, leveldb){
}

var name = leveldb
, db
, callTheCallback
, wrappedCallback;

if (typeof options === 'function') {
readyCallback = options;
options = {}; //options can not remain a function, the rest of the
//code expects it to be an object.
}

options = options || {};
callTheCallback = !!readyCallback;

var name = leveldb
, db;
options = options || {};

if (typeof leveldb === 'string') {
// do not call the callback immediately
// if we do not have a level() instance
callTheCallback = false;

// we are using LevelDown on node or level-js in the Browser
if (!options.db) {
options.db = require('./getdb');
}
leveldb = levelup(name, options);
}

if (readyCallback){
wrappedCallback = function(err, leveldb){
readyCallback(err, db);
};
}

leveldb = levelup(name, options, wrappedCallback);
}

// it may be an empty object if we are on browserify
if (typeof levelWriteStream === 'function') {
levelWriteStream(leveldb);
}

db = {
getStream: function(pattern, options) {
var query = utilities.createQuery(pattern, options);
return leveldb.createReadStream(query).
pipe(keyfilter(query));
}
getStream: function(pattern, options) {
var query = utilities.createQuery(pattern, options);
return leveldb.createReadStream(query).
pipe(keyfilter(query));
}
, get: utilities.wrapCallback('getStream')
, put: doAction('put', leveldb)
, del: doAction('del', leveldb)
Expand All @@ -56,13 +79,17 @@ module.exports = function levelgraph(leveldb, options) {
, searchStream: searchStream(leveldb, options)
, search: utilities.wrapCallback('searchStream')
, nav: function(start) {
return new Navigator({ start: start, db: this });
}
return new Navigator({ start: start, db: this });
}
};

db.joinStream = db.searchStream;
db.join = db.search;

if (callTheCallback && readyCallback) {
readyCallback(null, db);
}

return db;
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "levelgraph",
"version": "0.6.11",
"version": "0.6.12",
"description": "A graph database for Node.js and the browser built on top of LevelUp",
"main": "lib/levelgraph.js",
"scripts": {
Expand Down Expand Up @@ -52,7 +52,8 @@
"testling": "~1.5.3",
"zuul": "~1.0.4",
"coveralls": "~2.5.0",
"istanbul": "~0.1.45"
"istanbul": "~0.1.45",
"osenv": "0.0.3"
},
"dependencies": {
"xtend": "~2.1.1",
Expand Down
20 changes: 19 additions & 1 deletion test/triple_store_spec.js
@@ -1,6 +1,7 @@

var levelgraph = require('../lib/levelgraph')
, level = require('level-test')();
, level = require('level-test')()
, osenv = require('osenv');

describe('a basic triple store', function() {

Expand Down Expand Up @@ -239,3 +240,20 @@ describe('a basic triple store', function() {
});
});
});

describe('deferred open support', function() {

var db;

afterEach(function(done) {
db.close(done);
});

it('should call the callback if a level is passed', function(done) {
db = levelgraph(level(), done);
});

it('should call the callback if a level is not passed', function(done) {
db = levelgraph(osenv.tmpdir() + '_levelDeferred1', done);
});
});

0 comments on commit 6c12af3

Please sign in to comment.