Class: RedshiftConnector::DeltaQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_connector/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema:, table:, columns:, condition: nil) ⇒ DeltaQuery

Returns a new instance of DeltaQuery.



3
4
5
6
7
8
# File 'lib/redshift_connector/query.rb', line 3

def initialize(schema:, table:, columns:, condition: nil)
  @schema = schema
  @table = table
  @columns = columns
  @condition = condition
end

Instance Method Details

#descriptionObject



14
15
16
# File 'lib/redshift_connector/query.rb', line 14

def description
  "#{table_spec} (#{@columns.join(', ')}) where (#{@condition})"
end

#table_specObject



10
11
12
# File 'lib/redshift_connector/query.rb', line 10

def table_spec
  "#{@schema}.#{@table}"
end

#to_sqlObject



18
19
20
21
22
# File 'lib/redshift_connector/query.rb', line 18

def to_sql
  "select #{@columns.map {|c| %Q("#{c}") }.join(', ')}" \
      + " from #{table_spec}" \
      + (@condition ? " where #{@condition}" : '')
end