Class: Mode::Connector::Tables::RDBMS
- Inherits:
-
Object
- Object
- Mode::Connector::Tables::RDBMS
- Defined in:
- lib/mode/connector/tables/rdbms.rb
Instance Attribute Summary collapse
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
-
#table_schema ⇒ Object
readonly
Returns the value of attribute table_schema.
Instance Method Summary collapse
- #columns ⇒ Object
-
#initialize(data_source, table_schema, table_name) ⇒ RDBMS
constructor
A new instance of RDBMS.
- #is_pkey?(column_name) ⇒ Boolean
- #pkey_column_names ⇒ Object
-
#pkey_columns ⇒ Object
Primary Key Helpers.
- #preview ⇒ Object
- #row_count ⇒ Object
Constructor Details
#initialize(data_source, table_schema, table_name) ⇒ RDBMS
Returns a new instance of RDBMS.
9 10 11 12 13 |
# File 'lib/mode/connector/tables/rdbms.rb', line 9 def initialize(data_source, table_schema, table_name) @data_source = data_source @table_schema = table_schema @table_name = table_name end |
Instance Attribute Details
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
5 6 7 |
# File 'lib/mode/connector/tables/rdbms.rb', line 5 def data_source @data_source end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
7 8 9 |
# File 'lib/mode/connector/tables/rdbms.rb', line 7 def table_name @table_name end |
#table_schema ⇒ Object (readonly)
Returns the value of attribute table_schema.
6 7 8 |
# File 'lib/mode/connector/tables/rdbms.rb', line 6 def table_schema @table_schema end |
Instance Method Details
#columns ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mode/connector/tables/rdbms.rb', line 24 def columns return @columns unless @columns.nil? @columns = [] data_source.select(columns_query) do |row| column = row.dup column[:primary_key] = is_pkey?(row[:name]) ? true : false column[:is_nullable] = row[:is_nullable] == 'YES' ? true : false @columns << column end @columns end |
#is_pkey?(column_name) ⇒ Boolean
57 58 59 |
# File 'lib/mode/connector/tables/rdbms.rb', line 57 def is_pkey?(column_name) pkey_columns.any?{|pkey| pkey[:name] == column_name} end |
#pkey_column_names ⇒ Object
61 62 63 |
# File 'lib/mode/connector/tables/rdbms.rb', line 61 def pkey_column_names @pkey_column_names ||= pkey_columns.collect{|col| col[:name]} end |
#pkey_columns ⇒ Object
Primary Key Helpers
47 48 49 50 51 52 53 54 55 |
# File 'lib/mode/connector/tables/rdbms.rb', line 47 def pkey_columns return @pkey_columns unless @pkey_columns.nil? @pkey_columns = [] data_source.select(pkey_columns_query) do |row| @pkey_columns << row end @pkey_columns end |
#preview ⇒ Object
38 39 40 41 |
# File 'lib/mode/connector/tables/rdbms.rb', line 38 def preview return @preview unless @preview.nil? @preview = Mode::Connector::Selector.new(preview_query, data_source).perform! end |
#row_count ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/mode/connector/tables/rdbms.rb', line 15 def row_count return @row_count unless @row_count.nil? data_source.select(row_count_query) do |row| @row_count = row[:row_count] end @row_count end |