Class: Dumbo::Cast
Instance Attribute Summary collapse
-
#argument_type ⇒ Object
Returns the value of attribute argument_type.
-
#context ⇒ Object
Returns the value of attribute context.
-
#function_name ⇒ Object
Returns the value of attribute function_name.
-
#source_type ⇒ Object
Returns the value of attribute source_type.
-
#target_type ⇒ Object
Returns the value of attribute target_type.
Attributes inherited from PgObject
Instance Method Summary collapse
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
#argument_type ⇒ Object
Returns the value of attribute argument_type.
3 4 5 |
# File 'lib/dumbo/cast.rb', line 3 def argument_type @argument_type end |
#context ⇒ Object
Returns the value of attribute context.
3 4 5 |
# File 'lib/dumbo/cast.rb', line 3 def context @context end |
#function_name ⇒ Object
Returns the value of attribute function_name.
3 4 5 |
# File 'lib/dumbo/cast.rb', line 3 def function_name @function_name end |
#source_type ⇒ Object
Returns the value of attribute source_type.
3 4 5 |
# File 'lib/dumbo/cast.rb', line 3 def source_type @source_type end |
#target_type ⇒ Object
Returns the value of attribute target_type.
3 4 5 |
# File 'lib/dumbo/cast.rb', line 3 def target_type @target_type end |
Instance Method Details
#drop ⇒ Object
33 34 35 |
# File 'lib/dumbo/cast.rb', line 33 def drop "DROP CAST (#{source_type} AS #{target_type})" end |
#load_attributes ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dumbo/cast.rb', line 6 def load_attributes result = execute " SELECT\n format_type(st.oid,NULL) AS source_type,\n format_type(st.oid,NULL) AS argument_type,\n format_type(tt.oid,tt.typtypmod) AS target_type,\n proname AS function_name,\n CASE WHEN ca.castcontext = 'e' THEN NULL\n WHEN ca.castcontext = 'a' THEN 'ASSIGNMENT'\n ELSE 'IMPLICIT'\n END AS context\n\n FROM pg_cast ca\n JOIN pg_type st ON st.oid=castsource\n JOIN pg_type tt ON tt.oid=casttarget\n LEFT JOIN pg_proc pr ON pr.oid=castfunc\n LEFT OUTER JOIN pg_description des ON (des.objoid=ca.oid AND des.objsubid=0 AND des.classoid='pg_cast'::regclass)\n WHERE ca.oid = \#{oid}\n SQL\n\n result.first.each do |k,v|\n send(\"\#{k}=\",v) rescue nil\n end\n\n result.first\nend\n" |
#to_sql ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dumbo/cast.rb', line 37 def to_sql attributes = [] attributes << "WITH FUNCTION #{function_name}(#{source_type})" if function_name attributes << "WITHOUT FUNCTION" unless function_name attributes << context if context " CREATE CAST (\#{source_type} AS \#{target_type})\n \#{attributes.join(\"\\nAS \")};\n SQL\nend\n".gsub(/^ {6}/, '') |