Sha256: 4dbef6e6311db849a1efbe1410bb4d24a3d9204d4efe32e0eeccec498e6a516c

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

# frozen-string-literal: true
#
# The from_block extension changes Database#from so that blocks given
# to it are treated as virtual rows applying to the FROM clause,
# instead of virtual rows applying to the WHERE clause.  This will
# probably be made the default in the next major version of Sequel.
#
# This makes it easier to use table returning functions:
#
#   DB.from{table_function(1)}
#   # SELECT * FROM table_function(1)
#
# To load the extension into the database:
#
#   DB.extension :from_block
#
# Related module: Sequel::Database::FromBlock

#
module Sequel
  module Database::FromBlock
    # If a block is given, make it affect the FROM clause:
    #   DB.from{table_function(1)}
    #   # SELECT * FROM table_function(1)
    def from(*args, &block)
      if block
        @default_dataset.from(*args, &block)
      else
        super
      end
    end
    # SEQUEL5: Make this an empty module, since it will be the default behavior
  end

  Database.register_extension(:from_block, Database::FromBlock)
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/sequel-4.47.0/lib/sequel/extensions/from_block.rb
sequel-4.47.0 lib/sequel/extensions/from_block.rb
sequel-4.46.0 lib/sequel/extensions/from_block.rb