Sha256: 646cfdd8c577e80481063f7188d34b94db0fcb121d421bd8f82b3a658975a6cb

Contents?: true

Size: 816 Bytes

Versions: 5

Compression:

Stored size: 816 Bytes

Contents

require 'rom/sql/dsl'

module ROM
  module SQL
    # @api private
    class RestrictionDSL < DSL
      # @api private
      def call(&block)
        instance_exec(relations, &block)
      end

      # Returns a result of SQL EXISTS clause.
      #
      # @example
      #   users.where { exists(users.where(name: 'John')) }
      def exists(relation)
        ::ROM::SQL::Attribute[Types::Bool].meta(sql_expr: relation.dataset.exists)
      end

      private

      # @api private
      def method_missing(meth, *args, &block)
        if schema.key?(meth)
          schema[meth]
        else
          type = type(meth)

          if type
            ::ROM::SQL::Function.new(type)
          else
            ::Sequel::VIRTUAL_ROW.__send__(meth, *args, &block)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rom-sql-2.5.0 lib/rom/sql/restriction_dsl.rb
rom-sql-2.4.0 lib/rom/sql/restriction_dsl.rb
rom-sql-2.3.0 lib/rom/sql/restriction_dsl.rb
rom-sql-2.2.1 lib/rom/sql/restriction_dsl.rb
rom-sql-2.2.0 lib/rom/sql/restriction_dsl.rb