-
Notifications
You must be signed in to change notification settings - Fork 78
Neon
Neon is fast, minimal ruby binding for the neo4j. It provides a simple api to manipulate a Neo4J database instance hosted on a server or running as an embedded instance.
You start a session with a Neo4J database by creating a session. You can create a session with a REST server or an Embedded instance as follows :-
session = Neo4j::Session::Rest.new(url, options)
-
url
defaults to http://localhost:7474 -
options
defaults to {} and takes the following keys :-
options = {
directory: '', # Prefix the url with this directory
cypher: '/cypher', # Cypher path for the server
gremlin: '/ext/GremlinPlugin/graphdb/execute_script', # Gremlin path for the server
log: false, # Log activity or not
log_path: 'neon.log', # File name used for the log if :log is true
threads: 20, # Maximum number of threads to use
authentication: nil, # 'basic' or 'digest'
username: nil,
password: nil,
parser: MultiJsonParser
}
You can also quickly initialize using
Session::Rest.new("http://username:password@localhost:7474/mydirectory")
session = Session::Embedded.new(path_to_db, auto_tx)
-
path_to_db
is the path to the embedded database instance. -
auto_tx
is an optional boolean parameter that is true by default.
The first session created is the default session used by Neon modules. It can be accessed using the current attribute.
Session.current
# Set another session to be current. You get a boolean on whether it was successful or not
Session.set_current another_session # Returns true or false
# You can also do this
Session.current = another_session
another_session.current? # Check if this session is the current session or not?
Irrespective of the underlying session, you can use a common api there onwards i.e. you only make a choice on the session type during initialization and then forget about it. All further entities are linked to this session and provide a common interface for all core graph operations.
# Creating a session does not start it. You can start the session as follows
started? = session.start
# Stop a session
stopped? = session.stop
# Check if a session has been started i.e. is it running?
running? = session.running?
# All instance method calls are also available on Session and are called on the current session
started? = Session.start
stopped? = Session.stop
running? = Session.running?
# Location of the database
session.location
- For REST sessions this has no consequence as auto_tx cannot be disabled. You can though run multiple statements using transactions.
- For Embedded sessions auto_tx means all graph operations will be automatically wrapped inside a transaction which will be committed. You can disable auto_tx in which case all operations will need to be wrapped inside a transaction by the developer.
session.auto_tx # Defaults to true
session.auto_tx = false
WARNING: Much of the information in this wiki is out of day. We are in the process of moving things to readthedocs