Class: ETL::Generator::SurrogateKeyGenerator
- Defined in:
- lib/etl/generator/surrogate_key_generator.rb
Overview
Surrogate key generator.
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SurrogateKeyGenerator
constructor
Initialize the generator.
-
#next ⇒ Object
Get the next surrogate key.
- #table_name ⇒ Object
Methods inherited from Generator
Constructor Details
#initialize(options = {}) ⇒ SurrogateKeyGenerator
Initialize the generator
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/etl/generator/surrogate_key_generator.rb', line 13 def initialize(={}) @table = [:table] @target = [:target] @column = [:column] || 'id' @query = [:query] if table @surrogate_key = ETL::Engine.connection(target).select_value("SELECT max(#{column}) FROM #{table_name}") elsif query @surrogate_key = ETL::Engine.connection(target).select_value(query) end @surrogate_key = 0 if @surrogate_key.blank? @surrogate_key = @surrogate_key.to_i end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
9 10 11 |
# File 'lib/etl/generator/surrogate_key_generator.rb', line 9 def column @column end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
10 11 12 |
# File 'lib/etl/generator/surrogate_key_generator.rb', line 10 def query @query end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
7 8 9 |
# File 'lib/etl/generator/surrogate_key_generator.rb', line 7 def table @table end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/etl/generator/surrogate_key_generator.rb', line 8 def target @target end |
Instance Method Details
#next ⇒ Object
Get the next surrogate key
29 30 31 32 |
# File 'lib/etl/generator/surrogate_key_generator.rb', line 29 def next @surrogate_key ||= 0 @surrogate_key += 1 end |