Skip to content

neo4j-contrib/neo4j-script-procedures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neo4j Script Procedures

Build Status

This project demonstrates how to create dynamic procedures and functions on top of Neo4j’s built in infrastructure.

You can create JavaScript functions in your database that can be later run using the 'nashorn' engine.

This project requires Neo4j 3.x

Installation

  1. Download the jar from the latest release

  2. Copy it into your $NEO4J_HOME/plugins directory.

  3. Add dbms.security.procedures.unrestricted=scripts.* to $NEO4J_HOME/conf/neo4j.conf

  4. Restart your server.

Operations

The operations are:

create function
CALL scripts.function({name}, {code})

{"name" : "users",
 "code" : "function users() { return collection(db.findNodes(label('User'))) }"}
run function as procedure
CALL scripts.run({name}[, {params}])

CALL scripts.run('users', null)
CALL scripts.run('users')

-> returns one user per row
run function as function
RETURN scripts.run({name}[, {params}])

RETURN scripts.run('users', null) as users

or

RETURN scripts.run('users') as users

-> returns a list of users
list functions
CALL scripts.list()
helper functions
function label(s) { return org.neo4j.graphdb.Label.label(s); }

function type(s) { return org.neo4j.graphdb.RelationshipType.withName(s); }

function collection(it) { r=[]; while (it.hasNext()) r.push(it.next());  return Java.to(r); }

Building it yourself

This project uses maven, to build a jar-file with the procedure in this project, simply package the project with maven:

mvn clean package

This will produce a jar-file,target/neo4j-script-procedures-*-SNAPSHOT.jar, that can be copied in the $NEO4J_HOME/plugins directory of your Neo4j instance.

License

Apache License V2, see LICENSE