Class: Oraora::Meta::View

Inherits:
Object
  • Object
show all
Defined in:
lib/oraora/meta/view.rb

Instance Method Summary collapse

Methods inherited from Object

from_oci, #initialize

Constructor Details

This class inherits a constructor from Oraora::Meta::Object

Instance Method Details

#columns(column) ⇒ Object

Raises:



35
36
37
38
# File 'lib/oraora/meta/view.rb', line 35

def columns(column)
  raise NotExists if !@columns_hash[column]
  @columns_hash[column]
end

#describe(options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/oraora/meta/view.rb', line 23

def describe(options = {})
  "    View \#{@schema}.\#{@name}\n  HERE\nend\n".reset_indentation

#list(options = {}, filter = nil) ⇒ Object



29
30
31
32
33
# File 'lib/oraora/meta/view.rb', line 29

def list(options = {}, filter = nil)
  columns = @columns_hash.keys
  columns.select! { |c| c =~ /^#{Regexp.escape(filter).gsub('\*', '.*').gsub('\?', '.')}$/ } if filter
  columns
end

#load_from_oci(oci) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/oraora/meta/view.rb', line 10

def load_from_oci(oci)
  x = oci.select_one("SELECT 1 FROM all_views WHERE owner = :schema AND view_name = :name", @schema, @name).first
  raise NotExists if !x
  @columns = oci.pluck("SELECT column_name, column_id, data_type, data_length, data_precision, data_scale, char_used, char_length " +
                           "FROM all_tab_columns WHERE owner = :schema AND table_name = :name ORDER BY column_id", @schema, @name).collect do |col|
    Column.new(@schema, @name, col[0], id: col[1].to_i, type: col[2], length: col[3] && col[3].to_i,
               precision: col[4] && col[4].to_i, scale: col[5] && col[5].to_i, char_used: col[6],
               char_length: col[7] && col[7].to_i)
  end
  @columns_hash = Hash[@columns.collect { |col| [col.name, col] }]
  self
end

#typeObject



6
7
8
# File 'lib/oraora/meta/view.rb', line 6

def type
  'VIEW'
end