Sha256: d42282b0ea5af9d95ce52817d4c43c92e8616e0286737837ee46d1b76a6b962c

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

# Copyright 2021 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

# frozen_string_literal: true

module ActiveRecord
  module Type
    module Spanner
      class SpannerActiveRecordConverter
        def self.serialize_with_transaction_isolation_level type, value, isolation_level
          if type.respond_to? :serialize_with_isolation_level
            type.serialize_with_isolation_level value, isolation_level
          elsif type.respond_to? :serialize
            type.serialize value
          else
            value
          end
        end

        ##
        # Converts an ActiveModel::Type to a Spanner type code.
        def self.convert_active_model_type_to_spanner type # rubocop:disable Metrics/CyclomaticComplexity
          case type
          when NilClass then nil
          when ActiveModel::Type::Integer, ActiveModel::Type::BigInteger then :INT64
          when ActiveModel::Type::Boolean then :BOOL
          when ActiveModel::Type::String, ActiveModel::Type::ImmutableString then :STRING
          when ActiveModel::Type::Binary, ActiveRecord::Type::Spanner::Bytes then :BYTES
          when ActiveModel::Type::Float then :FLOAT64
          when ActiveModel::Type::Decimal then :NUMERIC
          when ActiveModel::Type::DateTime, ActiveModel::Type::Time, ActiveRecord::Type::Spanner::Time then :TIMESTAMP
          when ActiveModel::Type::Date then :DATE
          when ActiveRecord::Type::Json then :JSON
          when ActiveRecord::Type::Spanner::Array then [convert_active_model_type_to_spanner(type.element_type)]
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activerecord-spanner-adapter-1.6.1 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.6.0 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.5.1 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.5.0 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.4.4 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.4.3 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.4.2 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.4.1 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.4.0 lib/active_record/type/spanner/spanner_active_record_converter.rb
activerecord-spanner-adapter-1.3.1 lib/active_record/type/spanner/spanner_active_record_converter.rb