Class: Dumbo::RangeType

Inherits:
Type show all
Defined in:
lib/dumbo/range_type.rb

Instance Attribute Summary collapse

Attributes inherited from Type

#name, #type, #typrelid

Attributes inherited from PgObject

#oid

Instance Method Summary collapse

Methods inherited from Type

#drop, #get

Methods inherited from PgObject

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

Constructor Details

This class inherits a constructor from Dumbo::PgObject

Instance Attribute Details

#canonicalObject

Returns the value of attribute canonical.



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

def canonical
  @canonical
end

#collationObject

Returns the value of attribute collation.



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

def collation
  @collation
end

#subtypeObject

Returns the value of attribute subtype.



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

def subtype
  @subtype
end

#subtype_diffObject

Returns the value of attribute subtype_diff.



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

def subtype_diff
  @subtype_diff
end

#subtype_opclassObject

Returns the value of attribute subtype_opclass.



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

def subtype_opclass
  @subtype_opclass
end

Instance Method Details

#load_attributesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dumbo/range_type.rb', line 6

def load_attributes
  super
  result = execute "SELECT\nst.typname AS subtype,\nopc.opcname AS subtype_opclass,\ncol.collname AS collation,\nrngcanonical AS canonical,\nrngsubdiff AS  subtype_diff\nFROM pg_range\nLEFT JOIN pg_type st ON st.oid=rngsubtype\nLEFT JOIN pg_collation col ON col.oid=rngcollation\nLEFT JOIN pg_opclass opc ON opc.oid=rngsubopc\nWHERE rngtypid=\#{oid}\n"

  result.first.each do |k, v|
    send("#{k}=", v) rescue nil
  end
  result.first
end

#to_sqlObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dumbo/range_type.rb', line 28

def to_sql
  attr_str = [:subtype, :subtype_opclass, :collation, :canonical, :subtype_diff].map do |a|
    [a, public_send(a)]
  end.select { |k, v| v && v != '-' }.map { |k, v| "#{k.upcase}=#{v}" }.join(",\n  ")

  "CREATE TYPE \#{name} AS RANGE (\n\#{attr_str}\n);\n".gsub(/^ {6}/, '')
end