Sha256: c222973f29ad0d7b4d7bd5b00e831ab3b318d7f767de2b97a7da1dbf66c01934

Contents?: true

Size: 760 Bytes

Versions: 8

Compression:

Stored size: 760 Bytes

Contents

module Rasti
  module DB
    module TypeConverters
      module PostgresTypes
        class Array
          class << self

            DB_TYPE_REGEX = /^([a-z]+)\[\]$/

            def to_db?(type)
              !type.match(DB_TYPE_REGEX).nil?
            end

            def to_db(value, type)
              sub_type = type[0..-3]
              array = sub_type == 'hstore' ? value.map { |v| Sequel.hstore v } : value
              Sequel.pg_array array, sub_type
            end

            def from_db?(klass)
              defined?(Sequel::Postgres::PGArray) &&
              klass == Sequel::Postgres::PGArray
            end

            def from_db(value)
              value.to_a
            end

          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rasti-db-4.2.0 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-4.1.1 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-4.1.0 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-4.0.0 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-3.0.0 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-2.3.3 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-2.3.2 lib/rasti/db/type_converters/postgres_types/array.rb
rasti-db-2.3.1 lib/rasti/db/type_converters/postgres_types/array.rb