Class: Mode::Connector::Tables::RDBMS

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/connector/tables/rdbms.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_sourceObject (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_nameObject (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_schemaObject (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

#columnsObject



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

Returns:

  • (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_namesObject



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_columnsObject

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

#previewObject



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_countObject



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