Model Improvements


Table Joining


Dataset#join_table got a nice overhaul. You can now use any join type your database allows:

DB[:artist].join_table(:natural, :albums)
DB[:numbers].join_table(:cross, :numbers)

You can now specify the conditions as

Dataset#join_table also takes a block that yields three arguments:

Using the block you can specify conditions for complex joins without needing to know in advance what table aliases will be used.

Expanded SQL Syntax Support


SQL Case statements are now supported directly using hashes or arrays:

{:x > 1 => 1}.case(0)
# CASE WHEN x > 1 THEN 1 ELSE 0 END
[[{:x=>1}, 0], [:x < 1, 1], [:x > 1, 2]].case(-1)
# CASE WHEN x = 1 THEN 0 WHEN x < 1 THEN 1 WHEN x > 1 THEN 2
  ELSE -1 END

You should use an array instead of a hash for multiple conditions unless all conditions are orthogonal.

The SQL extract function has special syntax:

EXTRACT(day FROM date)

This syntax is now supported via the following ruby code:

:date.extract(:day)

Other Notable Changes


# Dataset#to_hash can take only one argument, in which case it uses

that argument to specify the key, and uses the entire hash for the
value.

# Dataset#graph can now take an array of columns to select from the

joined table via the :select option.

# Dataset#filter and similar methods now combine the block and

regular argument conditions if both are given, instead of ignoring
the regular argument conditions.

# Dataset#filter(false) can now be used to make sure that no records

are returned.  Dataset#filter(true) also works, but it's a no-op.
Before, these raised errors.

# Dataset#count does a subquery for a dataset using DISTINCT, since

the otherwise it would yield a count for the query without
DISTINCT.

ParseTree Support Officially Deprecated


The support for ParseTree-based block filters has officially been deprecated and will be removed in Sequel 2.2. To use the expression filters (which don't require ParseTree) inside blocks, use:

SEQUEL_NO_PARSE_TREE = true
require 'sequel'
# OR
require 'sequel'
Sequel.use_parse_tree = false

This is the default if ParseTree cannot be loaded. If ParseTree can be loaded, it remains the default, in order not to immediately break existing code.

With this set, you can use the expression filters inside of blocks:

dataset.filter{((:x + 1) & 10 < :y) & :z}

That doesn't gain you all that much, but there are some methods that feed block arguments into filter, such as the following:

dataset.first(5){((:x + 1) & 10 < :y) & :z}

Which will get you the first 5 records matching the condition.

Backwards Incompatible Changes