-
Notifications
You must be signed in to change notification settings - Fork 78
Session
There are currently two available types of session, one for connecting to a neo4j server and one for connecting to the embedded Neo4j database (which requires JRuby).
Using the Neo4j Server: :server_db
Open a IRB/Pry session:
require 'neo4j-core'
# Using Neo4j Server Cypher Database
session = Neo4j::Session.open(:server_db)
Example, Basic Authentication:
Neo4j::Session.open(:server_db, 'http://my.server', basic_auth: { username: 'username', password: 'password'})
HTTP(S) connections are handled using the Faraday gem. You can send options to its initialization method with an initialize
key.
Neo4j::Session.open(:server_db, 'http://my.server', basic_auth: { username: 'username', password: 'password'}, initialize: { ssl: { verify: true }})
See Faraday's documentation for more info about this.
Using the Neo4j Embedded Database, :embedded_db
# Using Neo4j Embedded Database
session = Neo4j::Session.open(:embedded_db, '/folder/db', auto_commit: true)
session.start
To stop the database (only supported via the embedded database) use
session.shutdown
session.running? #=> false
session.close # make the session not current/default
When a session has been created it will be stored in the Neo4j::Session
object.
Example, get the default session
session = Neo4j::Session.current
The default session is used by all operation unless specified as the last argument. For example create a node with a different session:
my_session = Neo4j::Session.create_session(:server_db, "http://localhost:7474")
Neo4j::Node.create(name: 'kalle', my_session)
When using the Neo4j Server: :server_db
, multiple sessions are supported.
The open_named
method controls named sessions. This method takes two extra parameters,
the second parameter is the session name, and the third parameter is whether the new session should over-ride the default session (becoming the session returned by calling Neo4j::Session.current
).
Valid options are true (always become current), false (never become current) and nil (become current if no existing current session).
Neo4j::Session.open_named(:server_db, :test, true, "https://localhost:7474")
session = Neo4j::Session.named :test # Returns the session named :test.
session = Neo4j::Session.current # Returns the session named :test, because the 'default' flag was set to true.
The open_named
method has been removed, you can now create named sessions using Neo4j::Session.open
. Use the name
and default
keys to control this behavior.
Neo4j::Session.open(:server_db, 'http://localhost:7474', name: :test, default: true)
Starting with Neo4j 2.2, the database provides basic authentication using tokens. The gem supports it starting with v3.1.0. Create a new session as you would otherwise and use the database username and password as basic authentication parameters. The gem will detect that the server expects credentials and a token, will see your username/password, and configure the session.
The fundamentals of the Authentication API Endpoint are accessible from the Neo4j::Server::CypherAuthentication
class. See specs at https://github.com/neo4jrb/neo4j-core/blob/master/spec/neo4j-server/e2e/cypher_authentication_spec.rb for a demonstration or YARD.
WARNING: Much of the information in this wiki is out of day. We are in the process of moving things to readthedocs