Class: Dumbo::Type

Inherits:
PgObject show all
Defined in:
lib/dumbo/type.rb

Direct Known Subclasses

BaseType, CompositeType, EnumType, RangeType

Instance Attribute Summary collapse

Attributes inherited from PgObject

#oid

Instance Method Summary collapse

Methods inherited from PgObject

#downgrade, #execute, identfied_by, #identify, #initialize, #upgrade

Constructor Details

This class inherits a constructor from Dumbo::PgObject

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/dumbo/type.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/dumbo/type.rb', line 3

def type
  @type
end

#typrelidObject

Returns the value of attribute typrelid.



3
4
5
# File 'lib/dumbo/type.rb', line 3

def typrelid
  @typrelid
end

Instance Method Details

#dropObject



26
27
28
# File 'lib/dumbo/type.rb', line 26

def drop
  "DROP TYPE #{name};"
end

#getObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dumbo/type.rb', line 13

def get
  case type
  when 'c'
    CompositeType.new(oid)
  when 'b'
    BaseType.new(oid)
  when 'r'
    RangeType.new(oid)
  when 'e'
    EnumType.new(oid)
  end
end

#load_attributesObject



6
7
8
9
10
11
# File 'lib/dumbo/type.rb', line 6

def load_attributes
  result = execute("SELECT typname, typtype, typrelid FROM pg_type WHERE oid = #{oid}").first
  @name = result['typname']
  @type = result['typtype']
  @typrelid = result['typrelid']
end