implicit_subquery.rb

lib/sequel/extensions/implicit_subquery.rb
Last Update: 2017-08-01 08:12:00 -0700

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