Sha256: b1b146eaaa50edd0bf3d4c09880d816ca61b9c4853fbf2a6bf500ffb13e4bbc3

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

require 'rom/sql/dsl'

module ROM
  module SQL
    # @api private
    class RestrictionDSL < DSL
      # @api private
      def call(&block)
        instance_exec(&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

3 entries across 3 versions & 1 rubygems

Version Path
rom-sql-2.1.0 lib/rom/sql/restriction_dsl.rb
rom-sql-2.0.0 lib/rom/sql/restriction_dsl.rb
rom-sql-2.0.0.rc1 lib/rom/sql/restriction_dsl.rb