Sha256: 988ea05aa80ace52a98bab28e04ebbc75fd3b4056d19b5fa44e80aa453a167be

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true

require 'rom/sql/schema/index_dsl'

module ROM
  module SQL
    class Schema < ROM::Schema
      # Specialized schema DSL with SQL-specific features
      #
      # @api public
      class DSL < ROM::Schema::DSL
        # @!attribute [r] index_dsl
        #   @return [IndexDSL] Index DSL instance (created only if indexes block is called)
        attr_reader :index_dsl

        # Define indexes within a block
        #
        # @api public
        def indexes(&)
          @index_dsl = IndexDSL.new(**options, &)
        end

        private

        # Return schema options
        #
        # @api private
        def opts
          if index_dsl
            opts = super

            { **opts, indexes: index_dsl.(relation, opts[:attributes]) }
          else
            super
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-sql-3.7.0 lib/rom/sql/schema/dsl.rb