Class: Blazer::Adapters::SalesforceAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/blazer/adapters/salesforce_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



34
35
36
# File 'lib/blazer/adapters/salesforce_adapter.rb', line 34

def preview_statement
  "SELECT Id FROM {table} 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
26
27
# File 'lib/blazer/adapters/salesforce_adapter.rb', line 4

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

  # remove comments manually
  statement = statement.gsub(/--.+/, "")
  # only supports single line /* */ comments
  # regex not perfect, but should be good enough
  statement = statement.gsub(/\/\*.+\*\//, "")

  # remove trailing semicolon
  statement = statement.sub(/;\s*\z/, "")

  begin
    response = client.query(statement)
    rows = response.map { |r| r.to_hash.except("attributes").values }
    columns = rows.any? ? response.first.to_hash.except("attributes").keys : []
  rescue => e
    error = e.message
  end

  [columns, rows, error]
end

#tablesObject



29
30
31
32
# File 'lib/blazer/adapters/salesforce_adapter.rb', line 29

def tables
  # cache
  @tables ||= client.describe.select { |r| r.queryable }.map(&:name)
end