Module: Torque::PostgreSQL::Adapter::Quoting

Included in:
Torque::PostgreSQL::Adapter
Defined in:
lib/torque/postgresql/adapter/quoting.rb

Constant Summary collapse

Name =
ActiveRecord::ConnectionAdapters::PostgreSQL::Name
Column =
ActiveRecord::ConnectionAdapters::PostgreSQL::Column
ColumnDefinition =
ActiveRecord::ConnectionAdapters::ColumnDefinition

Instance Method Summary collapse

Instance Method Details

#quote_default_expression(value, column) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/torque/postgresql/adapter/quoting.rb', line 24

def quote_default_expression(value, column)
  return super unless value.class <= Array || value.class <= Set

  type =
    if column.is_a?(ColumnDefinition) && column.options.try(:[], :array)
      # This is the general way
      lookup_cast_type(column.sql_type)
    elsif column.is_a?(Column) && column.array?
      # When using +change_column_default+
      lookup_cast_type_from_column(column)
    end

  type.nil? ? super : quote(type.serialize(value.to_a))
end

#quote_type_name(string, schema = nil) ⇒ Object

Quotes type names for use in SQL queries.



13
14
15
16
17
18
19
20
21
22
# File 'lib/torque/postgresql/adapter/quoting.rb', line 13

def quote_type_name(string, schema = nil)
  name_schema, table = string.to_s.scan(/[^".\s]+|"[^"]*"/)
  if table.nil?
    table = name_schema
    name_schema = nil
  end

  schema = schema || name_schema || 'public'
  Name.new(schema, table).quoted
end