Sha256: 8380ed104bfd4800c78c6129cbfea1e0dcf986a7a3c998cbefc813c2cee0a9b1

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

require 'dry-types'
require 'sequel'

Sequel.extension(*%i(pg_array pg_array_ops pg_json pg_json_ops))

module ROM
  module SQL
    module Types
      module PG
        # UUID

        UUID = Types::String

        # Array

        Array = Dry::Types::Definition
                .new(Sequel::Postgres::PGArray)

        def self.Array(db_type)
          Array.constructor(-> (v) { Sequel.pg_array(v, db_type) }).meta(type: db_type)
        end

        # JSON

        JSONArray = Dry::Types::Definition
                    .new(Sequel::Postgres::JSONArray)
                    .constructor(Sequel.method(:pg_json))

        JSONHash = Dry::Types::Definition
                   .new(Sequel::Postgres::JSONHash)
                   .constructor(Sequel.method(:pg_json))

        JSONOp = Dry::Types::Definition
                 .new(Sequel::Postgres::JSONOp)
                 .constructor(Sequel.method(:pg_json))

        JSON = JSONArray | JSONHash | JSONOp

        # JSONB

        JSONBArray = Dry::Types::Definition
                     .new(Sequel::Postgres::JSONBArray)
                     .constructor(Sequel.method(:pg_jsonb))

        JSONBHash = Dry::Types::Definition
                    .new(Sequel::Postgres::JSONBHash)
                    .constructor(Sequel.method(:pg_jsonb))

        JSONBOp = Dry::Types::Definition
                  .new(Sequel::Postgres::JSONBOp)
                  .constructor(Sequel.method(:pg_jsonb))

        JSONB = JSONBArray | JSONBHash | JSONBOp

        Bytea = Dry::Types::Definition
                .new(Sequel::SQL::Blob)
                .constructor(Sequel::SQL::Blob.method(:new))

        # MONEY

        Money = Types::Decimal
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rom-sql-1.0.0.beta2 lib/rom/sql/extensions/postgres/types.rb
rom-sql-1.0.0.beta1 lib/rom/sql/extensions/postgres/types.rb
rom-sql-0.9.1 lib/rom/sql/extensions/postgres/types.rb
rom-sql-0.9.0 lib/rom/sql/extensions/postgres/types.rb