Sha256: 142e3fc98cc6e4f9a465d34e5b9d54c7d035719e7a43f0afdd35a5c88b779e96

Contents?: true

Size: 1.26 KB

Versions: 12

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Torque
  module PostgreSQL
    module Adapter
      module Quoting

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

        # Quotes type names for use in SQL queries.
        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

        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
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
torque-postgresql-3.4.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.4.0 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.3.3 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.3.2 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.3.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.3.0 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.2.2 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.2.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.2.0 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.1.0 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.0.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-3.0.0 lib/torque/postgresql/adapter/quoting.rb