Class: Oraora::Meta::Schema

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Schema

Returns a new instance of Schema.



4
5
6
# File 'lib/oraora/meta/schema.rb', line 4

def initialize(name)
  @name = name
end

Class Method Details

.from_oci(oci, name) ⇒ Object



20
21
22
# File 'lib/oraora/meta/schema.rb', line 20

def self.from_oci(oci, name)
  new(name).load_from_oci(oci)
end

Instance Method Details

#describe(options = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/oraora/meta/schema.rb', line 24

def describe(options = {})
  "    Schema \#{@name}\n    Id:           \#{@id}\n    Created:      \#{@created}\n  HERE\nend\n".reset_indentation

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



32
33
34
35
36
37
# 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) ⇒ Object

Raises:



8
9
10
11
12
13
14
15
16
17
18
# 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