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

#parameter_bindingObject



42
43
44
45
46
47
48
49
# File 'lib/blazer/adapters/neo4j_adapter.rb', line 42

def parameter_binding
  proc do |statement, variables|
    variables.each_key do |k|
      statement = statement.gsub("{#{k}}") { "$#{k} " }
    end
    [statement, variables]
  end
end

#preview_statementObject



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

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

#quotingObject



38
39
40
# File 'lib/blazer/adapters/neo4j_adapter.rb', line 38

def quoting
  :backslash_escape
end

#run_statement(statement, comment, bind_params) ⇒ Object



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

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

  begin
    result = session.query("#{statement} /*#{comment}*/", bind_params)
    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
    error = Blazer::VARIABLE_MESSAGE if error.include?("Invalid input '$'")
  end

  [columns, rows, error]
end

#tablesObject



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

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