Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added neo4j adapter #129

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ var fortune = require('../lib/fortune');
*/
fortune({

adapter: "mongodb",
db: 'projects'
adapter: "neo4jdb",
db: 'projects',
debug:true

})

Expand Down
2 changes: 1 addition & 1 deletion examples/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var app = express();

fortune({

adapter: "mongodb",
adapter: "neo4jdb",
db: 'router_1',
router: app,
serviceName: "user-service"
Expand Down
3 changes: 2 additions & 1 deletion lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var adapters = {
mysql: 'fortune-relational',
psql: 'fortune-relational',
postgres: 'fortune-relational',
sqlite: 'fortune-relational'
sqlite: 'fortune-relational',
neo4jdb: './adapters/neo4jdb'
};


Expand Down
86 changes: 86 additions & 0 deletions lib/adapters/neo4jdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/***
This is a Neo4J adaptor prototype for Fortune
At the moment this is just a shell for the prototype
*/
var neo4j = require('node-neo4j');
var RSVP = require('rsvp');
var _ = require('lodash');
var moment = require("moment");
var Promise = RSVP.Promise;
var adapter = {};

adapter._models = {};
adapter._schemas = {};

adapter._init = function(options) {
/* This should handle the connection to the Neo4J Db */
/* this is for test only */
console.log("In Neo4J init");
// Store options
this._options = options;

};

adapter.model = function(name, schema, options) {

if(schema) {

// Actually set up a database
var connectionString = "http://localhost:7474";
var db = new neo4j(connectionString);


_.extend(db,options);
// Store the model name in a private key
db._name = name;

this._models[name] = db;
return db;
} else {
return this._models[name];
}
};

adapter.schema = function(name, schema, options, schemaCallback) {
_.each(schema, function(val, key) {
var obj = {}
, isArray = _.isArray(val)
, value = isArray ? val[0] : val
, isObject = _.isPlainObject(value)
, ref = isObject ? value.ref : value
, inverse = isObject ? value.inverse : undefined;

// Convert string to association object
if (typeof ref === 'string') {
obj.ref = ref;
obj.inverse = inverse;
schema[key] = isArray ? [obj] : obj;
}

// Wrap native type in object
if (typeof value === 'function') {
schema[key] = isArray ? [{type: schema[key]}] : {type: schema[key]};
}

});
this._schemas[name] = schema;
return schema;
};

adapter.create = function(model, id, resource) {

};

adapter.update = function(model, id, update) {

}

adapter.delete = function(model, id) {

};

adapter.find = function(model, query, projection) {

};

module.exports = adapter;
1 change: 1 addition & 0 deletions lib/fortune.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ function allowCrossDomain (cors) {
*/
function create (options) {
return new Fortune(options);

}

// Expose create method
Expand Down