Sha256: f59c7a496b75a43c22c672f57d36024fe42daf9e549576e1898432f4853386f8

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module ROM
  module SQL
    module Plugin
      # Nullify relation by
      #
      # @api public
      module Nullify
        if defined? JRUBY_VERSION
          # Returns a relation that will never issue a query to the database. It
          # implements the null object pattern for relations.
          # Dataset#nullify doesn't work on JRuby, hence we fall back to SQL
          #
          # @api public
          def nullify
            where { `1 = 0` }
          end
        else
          # Returns a relation that will never issue a query to the database. It
          # implements the null object pattern for relations.
          #
          # @see http://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/null_dataset_rb.html
          # @example result will always be empty, regardless if records exists
          #   users.where(name: 'Alice').nullify
          #
          # @return [SQL::Relation]
          #
          # @api public
          def nullify
            new(dataset.where { `1 = 0` }.__send__(__method__))
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-sql-3.7.0 lib/rom/sql/plugin/nullify.rb
rom-sql-3.6.5 lib/rom/sql/plugin/nullify.rb
rom-sql-3.6.4 lib/rom/sql/plugin/nullify.rb
rom-sql-3.6.3 lib/rom/sql/plugin/nullify.rb
rom-sql-3.6.2 lib/rom/sql/plugin/nullify.rb
rom-sql-3.6.1 lib/rom/sql/plugin/nullify.rb
rom-sql-3.6.0 lib/rom/sql/plugin/nullify.rb
rom-sql-4.0.0.alpha1 lib/rom/sql/plugin/nullify.rb
rom-sql-3.5.0 lib/rom/sql/plugin/nullify.rb
rom-sql-3.4.0 lib/rom/sql/plugin/nullify.rb
rom-sql-3.3.3 lib/rom/sql/plugin/nullify.rb
rom-sql-3.3.2 lib/rom/sql/plugin/nullify.rb
rom-sql-3.3.1 lib/rom/sql/plugin/nullify.rb
rom-sql-3.3.0 lib/rom/sql/plugin/nullify.rb
rom-sql-3.2.0 lib/rom/sql/plugin/nullify.rb