Class: Blazer::Adapters::Neo4jAdapter

Inherits:
BaseAdapter show all
Defined in:
lib/blazer/adapters/neo4j_adapter.rb

Instance Attribute Summary

Attributes inherited from BaseAdapter

#data_source

Instance Method Summary collapse

Methods inherited from BaseAdapter

#cachable?, #cancel, #cohort_analysis_statement, #cost, #explain, #initialize, #reconnect, #schema, #supports_cohort_analysis?

Constructor Details

This class inherits a constructor from Blazer::Adapters::BaseAdapter

Instance Method Details

#preview_statementObject



32
33
34
# File 'lib/blazer/adapters/neo4j_adapter.rb', line 32

def preview_statement
  "MATCH (n:{table}) RETURN n LIMIT 10"
end

#run_statement(statement, comment) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/blazer/adapters/neo4j_adapter.rb', line 4

def run_statement(statement, comment)
  columns = []
  rows = []
  error = nil

  begin
    result = session.query("#{statement} /*#{comment}*/")
    columns = result.columns.map(&:to_s)
    rows = []
    result.each do |row|
      rows << columns.map do |c|
        v = row.send(c)
        v = v.properties if v.respond_to?(:properties)
        v
      end
    end
  rescue => e
    error = e.message
  end

  [columns, rows, error]
end

#tablesObject



27
28
29
30
# File 'lib/blazer/adapters/neo4j_adapter.rb', line 27

def tables
  result = session.query("CALL db.labels()")
  result.rows.map(&:first)
end