Sha256: 7f08e03cdcf0f10d837e2ed905b2f3a23e834a99820cda511b6b444e485e0843

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'sequel/core'
require 'sequel/sql'

require 'rom/types'
require 'rom/sql/type_dsl'

module ROM
  module SQL
    module Types
      include ROM::Types

      # Define a foreign key attribute type
      #
      # @example with default Int type
      #   attribute :user_id, Types.ForeignKey(:users)
      #
      # @example with a custom type
      #   attribute :user_id, Types.ForeignKey(:users, Types::UUID)
      #
      # @return [Dry::Types::Nominal]
      #
      # @api public
      def self.ForeignKey(relation, type = Types::Integer.meta(index: true))
        super
      end

      # Define a complex attribute type using Type DSL
      #
      # @example
      #   attribute :meta, Types.define(Types::JSON) do
      #     input { Types::PG::JSON }
      #     output { Types::Coercible::Hash }
      #   end
      #
      # @return [Dry::Types::Nominal]
      #
      # @api public
      def self.define(value_type, &block)
        TypeDSL.new(value_type).call(&block)
      end

      Serial = Integer.meta(primary_key: true)

      Blob = Constructor(Sequel::SQL::Blob, &Sequel::SQL::Blob.method(:new))

      Void = Nil
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rom-sql-3.6.4 lib/rom/sql/types.rb
rom-sql-3.6.3 lib/rom/sql/types.rb
rom-sql-3.6.2 lib/rom/sql/types.rb
rom-sql-3.6.1 lib/rom/sql/types.rb
rom-sql-3.6.0 lib/rom/sql/types.rb
rom-sql-3.5.0 lib/rom/sql/types.rb
rom-sql-3.4.0 lib/rom/sql/types.rb
rom-sql-3.3.3 lib/rom/sql/types.rb
rom-sql-3.3.2 lib/rom/sql/types.rb
rom-sql-3.3.1 lib/rom/sql/types.rb
rom-sql-3.3.0 lib/rom/sql/types.rb
rom-sql-3.2.0 lib/rom/sql/types.rb