Class: Oraora::Meta::Table
Instance Method Summary collapse
- #columns(column) ⇒ Object
- #describe(options = {}) ⇒ Object
- #list(options = {}, filter = nil) ⇒ Object
- #load_from_oci(oci) ⇒ Object
- #type ⇒ Object
Methods inherited from Object
Constructor Details
This class inherits a constructor from Oraora::Meta::Object
Instance Method Details
#columns(column) ⇒ Object
36 37 38 39 |
# File 'lib/oraora/meta/table.rb', line 36 def columns(column) raise NotExists if !@columns_hash[column] @columns_hash[column] end |
#describe(options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/oraora/meta/table.rb', line 23 def describe( = {}) " Table \#{@schema}.\#{@name}\n Partitioned: \#{@partitioned}\n HERE\nend\n".reset_indentation |
#list(options = {}, filter = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/oraora/meta/table.rb', line 30 def list( = {}, filter = nil) columns = @columns_hash.keys columns.select! { |c| c =~ /^#{Regexp.escape(filter).gsub('\*', '.*').gsub('\?', '.')}$/ } if filter columns end |
#load_from_oci(oci) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/oraora/meta/table.rb', line 10 def load_from_oci(oci) @partitioned = oci.select_one("SELECT partitioned FROM all_tables WHERE owner = :schema AND table_name = :name", @schema, @name).first raise NotExists if !@partitioned @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 |
#type ⇒ Object
6 7 8 |
# File 'lib/oraora/meta/table.rb', line 6 def type 'TABLE' end |