Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added functionality to execture Gremlin Scripts on the graph services…

…, was able to wire up the function and build a working starting point, am not getting callbacks to fire when results are complete
  • Loading branch information...
commit 4824654a827725790a2e5251d38e4c82df97d0ec 1 parent 043ffc3
Stephen Rivas JR authored
Showing with 48 additions and 0 deletions.
  1. +48 −0 lib/GraphDatabase._coffee
View
48 lib/GraphDatabase._coffee
@@ -241,6 +241,54 @@ module.exports = class GraphDatabase
catch error
throw adjustError error
+ # wrapper around the Gremlin plugin to execute scripts bundled with
+ # Neo4j. Pass in the Gremlin script as a string, and optionally script
+ # parameters as a map -- recommended for both perf and security!
+ # http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html
+ # returns...
+ gremlin: (script, params, _) ->
+ try
+ services = @getServices _
+ endpoint = services.gremlin or
+ services.extensions?.GremlinPlugin?['execute_script']
+
+ if not endpoint
+ throw new Error 'Gremlin plugin not installed'
+
+ response = @_request.post
+ uri: endpoint
+ json: if params then {script, params} else {script}
+ , _
+
+ # XXX workaround for neo4j silent failures for invalid queries:
+ if response.statusCode is status.NO_CONTENT
+ throw new Error """
+ Unknown Neo4j error for Gremlin script:
+
+ #{script}
+
+ """
+
+ if response.statusCode isnt status.OK
+ # Database error
+ throw response
+
+ # Success: build result maps, and transform nodes/relationships
+ body = response.body # JSON already parsed by request
+ results = for row in body
+ for value, i in row
+ if value and typeof value is 'object' and value.self
+ if value.type then new Relationship this, value
+ else new Node this, value
+ else
+ value
+ row
+
+ return results
+
+ catch error
+ throw adjustError error
+
# XXX temporary backwards compatibility shim for query() argument order:
do (actual = @::query) =>
@::query = (query, params, callback) ->
Please sign in to comment.
Something went wrong with that request. Please try again.