class Oraora::Meta::Schema

Public Class Methods

from_oci(oci, name) click to toggle source
# File lib/oraora/meta/schema.rb, line 20
def self.from_oci(oci, name)
  new(name).load_from_oci(oci)
end
new(name) click to toggle source
# File lib/oraora/meta/schema.rb, line 4
def initialize(name)
  @name = name
end

Public Instance Methods

describe(options = {}) click to toggle source
# File lib/oraora/meta/schema.rb, line 24
      def describe(options = {})
        <<-HERE.reset_indentation
          Schema #{@name}
          Id:           #{@id}
          Created:      #{@created}
        HERE
      end
list(options = {}, filter = nil) click to toggle source
# File lib/oraora/meta/schema.rb, line 32
def list(options = {}, filter = nil)
  objects = @objects.collect(&:first)
  objects.reject! { |o| o =~ /^ISEQ\$\$/ || o =~ /^SYS_/ || o =~ /^ORA_/ } unless options['a']
  objects.select! { |o| o =~ /^#{Regexp.escape(filter).gsub('\*', '.*').gsub('\?', '.')}$/ } if filter
  objects
end
load_from_oci(oci) click to toggle source
# File lib/oraora/meta/schema.rb, line 8
def load_from_oci(oci)
  @id, @created = oci.select_one("SELECT user_id, created FROM all_users WHERE username = :name", @name)
  raise NotExists if !@id
  @id = @id.to_i
  @objects = oci.pluck("SELECT object_name, min(object_type) object_type FROM all_objects
                         WHERE owner = :name
                           AND object_type IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW', 'SEQUENCE')
                         GROUP BY object_name
                         ORDER BY object_name", @name)
  self
end