Class: Dumbo::CompositeType
- Defined in:
- lib/dumbo/composite_type.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
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
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/dumbo/composite_type.rb', line 3 def attributes @attributes end |
Instance Method Details
#load_attributes ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dumbo/composite_type.rb', line 5 def load_attributes super res = execute " SELECT\n attname,\n format_type(t.oid,NULL) AS typname\n FROM pg_attribute att\n JOIN pg_type t ON t.oid=atttypid\n\n WHERE att.attrelid=\#{typrelid}\n ORDER by attnum\n SQL\n\n attribute = Struct.new(:name, :type)\n @attributes = res.map{|r| attribute.new(r['attname'],r['typname'])}\nend\n" |
#to_sql ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/dumbo/composite_type.rb', line 22 def to_sql attr_str = attributes.map{|a| "#{a.name} #{a.type}"}.join(",\n ") " CREATE TYPE \#{name} AS (\n \#{attr_str}\n );\n SQL\nend\n".gsub(/^ {6}/, '') |