Sha256: 3083fd124fb617254a196ee0616b5478a21d3d4cede8aa8636f7828f20a62979

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

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::Definition]
      #
      # @api public
      def self.ForeignKey(relation, type = Types::Int.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::Definition]
      #
      # @api public
      def self.define(value_type, &block)
        TypeDSL.new(value_type).call(&block)
      end

      Serial = Int.meta(primary_key: true)

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

      Void = Nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rom-sql-2.5.0 lib/rom/sql/types.rb
rom-sql-2.4.0 lib/rom/sql/types.rb
rom-sql-2.3.0 lib/rom/sql/types.rb
rom-sql-2.2.1 lib/rom/sql/types.rb
rom-sql-2.2.0 lib/rom/sql/types.rb
rom-sql-2.1.0 lib/rom/sql/types.rb
rom-sql-2.0.0 lib/rom/sql/types.rb
rom-sql-2.0.0.rc1 lib/rom/sql/types.rb