Skip to content

Commit

Permalink
Merge branch 'v0.2.5' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmusso committed Oct 30, 2013
2 parents 544bb71 + bd60ff9 commit 3e6a09a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mogwai",
"version": "0.2.4",
"version": "0.2.5",
"description": "Object-to-graph mapper for Node.js using Gremlin in Mongoose style (very alpha work)",
"main": "index.js",
"scripts": {
Expand Down
42 changes: 30 additions & 12 deletions src/clients/rexster.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = RexsterClient = (function(){
return callback(new Error("Script must be an instance of GroovyScript"));
}

var self = this;
var settings = this.mogwai.settings;
var url = "http://"+ settings.host +":"+ settings.port +"/graphs/"+ settings.graph + path;

Expand All @@ -52,21 +53,38 @@ module.exports = RexsterClient = (function(){
};

request.get(options, function(err, res, body) {
if (err) {
// HTTP/request error
return callback(err);
}

if (!body.success) {
// Internal Rexster error
return callback(body.error);
}

// Success!
return callback(null, body);
self.handleResponse(err, body, callback);
});
};

/**
* Handle the HTTP response returned by Rexster upon request, checking
* whether it was successful or not.
*
* @param {String} err
* @param {String} body - HTTP response body
* @param {Function} callback
*/
RexsterClient.prototype.handleResponse = function(err, body, callback) {
if (err) {
// HTTP/request error
return callback(new Error(err));
}

if (body.success === false || body.error) {
// Database error
return callback(new Error(body.error));
}

if (body.message) {
// Rexster error
return callback(new Error(body.message));
}

// Success!
return callback(null, body);
};

/**
* Sends a Gremlin request to the server for execution, and returns the
* response.
Expand Down
10 changes: 7 additions & 3 deletions src/gremlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ module.exports = (function () {
/**
* Asynchronously ask the client to send the script to the database for
* execution, and return elements as appropriate model instances if
* available.
* available. Won't initialize elements in case of an error.
*
* @param {Function} callback
*/
Gremlin.prototype.query = function(callback) {
var initializer = this.client.mogwai.elementInitializer;

this.client.executeGremlin(this.script, this.params, function(err, body) {
var elements = initializer.initElements(body);
var elements = [];

return callback(null, elements);
if (!err) {
elements = initializer.initElements(body);
}

return callback(err, elements);
});
};

Expand Down

0 comments on commit 3e6a09a

Please sign in to comment.