implicit_subquery.rb

Path: lib/sequel/extensions/implicit_subquery.rb
Last Update: Fri Oct 06 03:25:22 +0000 2017

frozen-string-literal: true

The implicit_subquery extension changes most dataset methods that return modified datasets to implicitly call from_self if the database currently uses raw SQL. Sequel‘s by default does not do this:

  DB["SELECT * FROM table"].select(:column).sql
  # => "SELECT * FROM table"

With this extension, datasets that use raw SQL are implicitly wrapped in a subquery:

  DB["SELECT * FROM table"].select(:column).sql
  # => "SELECT column FROM (SELECT * FROM table) AS t1"

To add this extension to an existing dataset:

  ds = ds.extension(:implicit_subquery)

To set this as the default behavior for all datasets on a single database:

  DB.extension(:implicit_subquery)

Related module: Sequel::Dataset::ImplicitSubquery

[Validate]