Class: Blazer::Adapters::InfluxdbAdapter

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



46
47
48
# File 'lib/blazer/adapters/influxdb_adapter.rb', line 46

def parameter_binding
  # not supported
end

#preview_statementObject



37
38
39
# File 'lib/blazer/adapters/influxdb_adapter.rb', line 37

def preview_statement
  "SELECT * FROM {table} LIMIT 10"
end

#quotingObject



42
43
44
# File 'lib/blazer/adapters/influxdb_adapter.rb', line 42

def quoting
  :backslash_escape
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
28
29
30
31
# File 'lib/blazer/adapters/influxdb_adapter.rb', line 4

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

  begin
    result = client.query(statement, denormalize: false).first

    if result
      columns = result["columns"]
      rows = result["values"]

      # parse time columns
      # current approach isn't ideal, but result doesn't include types
      # another approach would be to check the format
      time_index = columns.index("time")
      if time_index
        rows.each do |row|
          row[time_index] = Time.parse(row[time_index]) if row[time_index]
        end
      end
    end
  rescue => e
    error = e.message
  end

  [columns, rows, error]
end

#tablesObject



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

def tables
  client.list_series
end