Sha256: 979b9a85b348e47515f6de22218d64df7c9dff1dcdfd6077222642e89ccc21f3

Contents?: true

Size: 1.53 KB

Versions: 21

Compression:

Stored size: 1.53 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    module CockroachDB
      module Quoting
        private

        # CockroachDB does not allow inserting integer values into string
        # columns, but ActiveRecord expects this to work. CockroachDB will
        # however allow inserting string values into integer columns. It will
        # try to parse string values and convert them to integers so they can be
        # inserted in integer columns.
        #
        # We take advantage of this behavior here by forcing numeric values to
        # always be strings. Then, we won't have to make any additional changes
        # to ActiveRecord to support inserting integer values into string
        # columns.
        #
        # For spatial types, data is stored as Well-known Binary (WKB) strings
        # (https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)
        # but when creating objects, using RGeo features is more convenient than
        # converting to WKB, so this does it automatically.
        def _quote(value)
          if value.is_a?(Numeric)
            "'#{quote_string(value.to_s)}'"
          elsif RGeo::Feature::Geometry.check_type(value)
            "'#{RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)}'"
          elsif value.is_a?(RGeo::Cartesian::BoundingBox)
            "'#{value.min_x},#{value.min_y},#{value.max_x},#{value.max_y}'::box"
          else
            super
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
activerecord-cockroachdb-adapter-6.1.11 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.10 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.9 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.8 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.7 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.6 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.5 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.4 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.3 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.0.2 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.2 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.0.1 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.1 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.0.0 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.0 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.0.0.pre.beta.5 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.0.pre.beta.3 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.0.pre.beta.2 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.0.0.pre.beta.4 lib/active_record/connection_adapters/cockroachdb/quoting.rb
activerecord-cockroachdb-adapter-6.1.0beta1 lib/active_record/connection_adapters/cockroachdb/quoting.rb