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 <<-SQL SELECT attname, format_type(t.oid,NULL) AS typname FROM pg_attribute att JOIN pg_type t ON t.oid=atttypid WHERE att.attrelid=#{typrelid} ORDER by attnum SQL attribute = Struct.new(:name, :type) @attributes = res.map { |r| attribute.new(r['attname'], r['typname']) } end |
#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 ") <<-SQL.gsub(/^ {6}/, '') CREATE TYPE #{name} AS ( #{attr_str} ); SQL end |