Class: Dumbo::RangeType
Instance Attribute Summary collapse
-
#canonical ⇒ Object
Returns the value of attribute canonical.
-
#collation ⇒ Object
Returns the value of attribute collation.
-
#subtype ⇒ Object
Returns the value of attribute subtype.
-
#subtype_diff ⇒ Object
Returns the value of attribute subtype_diff.
-
#subtype_opclass ⇒ Object
Returns the value of attribute subtype_opclass.
Attributes inherited from Type
Attributes inherited from PgObject
Instance Method Summary collapse
Methods inherited from Type
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
#canonical ⇒ Object
Returns the value of attribute canonical.
3 4 5 |
# File 'lib/dumbo/range_type.rb', line 3 def canonical @canonical end |
#collation ⇒ Object
Returns the value of attribute collation.
3 4 5 |
# File 'lib/dumbo/range_type.rb', line 3 def collation @collation end |
#subtype ⇒ Object
Returns the value of attribute subtype.
3 4 5 |
# File 'lib/dumbo/range_type.rb', line 3 def subtype @subtype end |
#subtype_diff ⇒ Object
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_opclass ⇒ Object
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_attributes ⇒ Object
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_sql ⇒ Object
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 |