Sha256: 7a5a398dd3ce026890b3e66975a5c38fb64c85a9ee7088daff943278bd0275c4

Contents?: true

Size: 1016 Bytes

Versions: 7

Compression:

Stored size: 1016 Bytes

Contents

# encoding: utf-8
require "neo4j"

module Neo4jrb
  class Client

    def self.open(location)
      session = start_session_at(location)
      Neo4jrb::Client.new(session)
    end

    def count_nodes
      Neo4j::Transaction.run { @session.graph_db.all_nodes.count }
    end

    def session
      Neo4j::Session.current
    end

    def execute_query(statement, &block)
      resultset = []
      Neo4j::Session.query(statement).each do |result|
        objects = result.members.map { |member| result.send member }
        if block_given?
          block.call(objects)
        else
          resultset << objects
        end
      end
      resultset
    end

    private
    def initialize(session)
      @last_start = Time.at(0).utc
      @session    = session
    end

    def self.start_session_at(location)
      if Neo4j::Session.current.nil?
        session = ::Neo4j::Session.open(:embedded_db, location, :auto_commit => true)
        session.start
      end
      Neo4j::Session.current
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
logstash-input-neo4j-2.0.8-java lib/logstash/inputs/neo4j-client.rb
logstash-input-neo4j-2.0.6-java lib/logstash/inputs/neo4j-client.rb
logstash-input-neo4j-2.0.5-java lib/logstash/inputs/neo4j-client.rb
logstash-input-neo4j-2.0.2-java lib/logstash/inputs/neo4j-client.rb
logstash-input-neo4j-2.0.1-java lib/logstash/inputs/neo4j-client.rb
logstash-input-neo4j-0.9.2-java lib/logstash/inputs/neo4j-client.rb
logstash-input-neo4j-0.9.1-java lib/logstash/inputs/neo4j-client.rb