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\n      st.typname AS subtype,\n      opc.opcname AS subtype_opclass,\n      col.collname AS collation,\n      rngcanonical AS canonical,\n      rngsubdiff AS  subtype_diff\n    FROM pg_range\n    LEFT JOIN pg_type st ON st.oid=rngsubtype\n    LEFT JOIN pg_collation col ON col.oid=rngcollation\n    LEFT JOIN pg_opclass opc ON opc.oid=rngsubopc\n    WHERE rngtypid=\#{oid}\n    SQL\n\n  result.first.each do |k,v|\n    send(\"\#{k}=\",v) rescue nil\n  end\n  result.first\nend\n"

#to_sqlObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dumbo/range_type.rb', line 31

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  SQL\nend\n".gsub(/^ {6}/, '')