Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/activerecord-postgres-array/activerecord.rb

Constant Summary collapse

POSTGRES_ARRAY_TYPES =
%w( string text integer float decimal datetime timestamp time date binary boolean )

Instance Method Summary collapse

Instance Method Details

#native_database_types_with_array(*args) ⇒ Object



37
38
39
# File 'lib/activerecord-postgres-array/activerecord.rb', line 37

def native_database_types_with_array(*args)
  native_database_types_without_array.merge(POSTGRES_ARRAY_TYPES.inject(Hash.new) {|h, t| h.update("#{t}_array".to_sym => {:name => "#{native_database_types_without_array[t.to_sym][:name]}[]"})})
end

#quote_with_array(value, column = nil) ⇒ Object

Quotes a value for use in an SQL statement



43
44
45
46
47
48
49
# File 'lib/activerecord-postgres-array/activerecord.rb', line 43

def quote_with_array(value, column = nil)
  if value && column && column.sql_type =~ /\[\]$/
    raise ArrayTypeMismatch, "#{column.name} must be an Array or have a valid array value (#{value})" unless value.kind_of?(Array) || value.valid_postgres_array?
    return value.to_postgres_array
  end
  quote_without_array(value,column)
end