Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Inherits:
Object
  • Object
show all
Includes:
PgArrayParser
Defined in:
lib/ar_jdbc_pg_array/schema.rb

Overview

:nodoc:

Constant Summary

Constants included from PgArrayParser

PgArrayParser::CURLY_BRACKETS, PgArrayParser::ESCAPE_HASH, PgArrayParser::NIL, PgArrayParser::NULL, PgArrayParser::SQUARE_BRACKETS

Instance Method Summary collapse

Methods included from PgArrayParser

#_parse_pgarray, #_parse_safe_pgarray, #_prepare_pg_string_array, #_remap_array, #parse_numeric_pgarray, #parse_pgarray, #parse_safe_pgarray, #prepare_pg_float_array, #prepare_pg_integer_array, #prepare_pg_safe_array, #prepare_pg_text_array

Instance Method Details

#add_column_with_postgresql_arrays(table, column, type, options = {}) ⇒ Object



219
220
221
222
223
224
# File 'lib/ar_jdbc_pg_array/schema.rb', line 219

def add_column_with_postgresql_arrays(table, column, type, options = {})
  if type.to_s =~ /^(.+)_array$/ && options[:default].is_a?(Array)
    options = options.merge(:default => prepare_array_for_arel_by_base_type(options[:default], $1))
  end
  add_column_without_postgresql_arrays(table, column, type, options)
end

#prepare_array_for_arel_by_base_type(value, base_type) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/ar_jdbc_pg_array/schema.rb', line 167

def prepare_array_for_arel_by_base_type(value, base_type)
  case base_type.to_sym
    when :integer
      prepare_pg_integer_array(value)
    when :float
      prepare_pg_float_array(value)
    when :string, :text, :other
      prepare_pg_text_array(value)
    when :datetime, :timestamp, :time
      prepare_pg_string_array(value, base_type)
    when :decimal, :boolean, :date, :safe
      prepare_pg_safe_array(value)
    else
      raise "Unsupported array base type #{base_type} for arel"
  end
end

#prepare_pg_string_array(value, base_type, column = nil) ⇒ Object



184
185
186
187
188
189
190
191
# File 'lib/ar_jdbc_pg_array/schema.rb', line 184

def prepare_pg_string_array(value, base_type, column = nil)
  base_column = if column
                  column.base_column
                else
                  PostgreSQLColumn::BASE_TYPE_COLUMNS[base_type.to_sym]
                end
  _prepare_pg_string_array(value) { |v| quote_without_postgresql_arrays(v, base_column) }
end

#quote_array_by_base_type(value, base_type, column = nil) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ar_jdbc_pg_array/schema.rb', line 155

def quote_array_by_base_type(value, base_type, column = nil)
  case base_type.to_sym
  when :integer, :float, :decimal, :boolean, :date, :safe, :datetime, :timestamp, :time
    "'#{ prepare_array_for_arel_by_base_type(value, base_type) }'"
  when :string, :text, :other
    pa = prepare_array_for_arel_by_base_type(value, base_type)
    "'#{ quote_string(pa) }'"
  else
    "'#{ prepare_pg_string_array(value, base_type, column) }'"
  end
end

#quote_with_postgresql_arrays(value, column = nil) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/ar_jdbc_pg_array/schema.rb', line 146

def quote_with_postgresql_arrays(value, column = nil)
  if Array === value && column && "#{column.type}" =~ /^(.+)_array$/
    quote_array_by_base_type(value, $1, column)
  else
    quote_without_postgresql_arrays(value, column)
  end
end

#type_cast_with_postgresql_arrays(value, column) ⇒ Object



237
238
239
240
241
242
243
# File 'lib/ar_jdbc_pg_array/schema.rb', line 237

def type_cast_with_postgresql_arrays(value, column)
  if Array === value && column && "#{column.type}" =~ /^(.+)_array$/
    prepare_array_for_arel_by_base_type(value, $1)
  else
    type_cast_without_postgresql_arrays(value, column)
  end
end

#type_to_sql_with_postgresql_arrays(type, limit = nil, precision = nil, scale = nil) ⇒ Object



227
228
229
230
231
232
233
# File 'lib/ar_jdbc_pg_array/schema.rb', line 227

def type_to_sql_with_postgresql_arrays(type, limit = nil, precision = nil, scale = nil)
  if type.to_s =~ /^(.+)_array$/
    type_to_sql_without_postgresql_arrays($1.to_sym, limit, precision, scale) + '[]'
  else
    type_to_sql_without_postgresql_arrays(type, limit, precision, scale)
  end
end