Class: Nquery::SchemaExplorer

Inherits:
Object
  • Object
show all
Defined in:
lib/nquery/schema_explorer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_source) ⇒ SchemaExplorer

Returns a new instance of SchemaExplorer.



9
10
11
# File 'lib/nquery/schema_explorer.rb', line 9

def initialize(data_source)
  @data_source = data_source
end

Class Method Details

.tables_for(data_source) ⇒ Object



5
6
7
# File 'lib/nquery/schema_explorer.rb', line 5

def self.tables_for(data_source)
  new(data_source).tables
end

Instance Method Details

#tablesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nquery/schema_explorer.rb', line 13

def tables
  return [] unless @data_source

  adapter = DataSources::Adapter.for(@data_source)
  adapter.tables.map do |table|
    {
      name: table,
      columns: adapter.columns(table)
    }
  end
rescue StandardError => e
  Rails.logger.error("[Nquery::SchemaExplorer] #{e.class}: #{e.message}\n#{e.backtrace&.first(8)&.join("\n")}")
  []
end