ANN: Sequel 2.5.0 Released

  • Sequel provides thread safety, connection pooling and a concise DSL
    for constructing database queries and table schemas.
  • Sequel also includes a lightweight but comprehensive ORM layer for
    mapping records to Ruby objects and handling associated records.
  • Sequel supports advanced database features such as prepared
    statements, bound variables, master/slave configurations, and
    database sharding.
  • Sequel makes it easy to deal with multiple records without having
    to break your teeth on SQL.
  • Sequel currently has adapters for ADO, DB2, DBI, Informix, JDBC,
    MySQL, ODBC, OpenBase, Oracle, PostgreSQL and SQLite3.

Sequel 2.5.0 has been released and should be available on the gem
mirrors. The 2.5.0 release adds numerous minor features and

New Features

  • The values that are used to insert/update records can now be
    scoped similar to how filter expressions can be scoped.
    set_defaults is used to set defaults which can be overridden,
    and set_overrides is used to set defaults which cannot be

    # => INSERT INTO t (x) VALUES (1)
    # => INSERT INTO t (x) VALUES (2)
    # => INSERT INTO t (x, y) VALUES (1, 2)
    # => INSERT INTO t (x) VALUES (1)

    The difference between set_defaults and set_overrides is that
    with set_defaults, the last value takes precedence, while with
    set_overrides, the first value takes precedence.

  • The schema generators now support creating and altering tables
    with composite primary and/or foreign keys:

    DB.create_table(:items) do
    integer :id
    text :name
    primary_key [:id, :name]
    foreign_key [:id, :name], :other_table,
    :key=>[:item_id, :item_name]

    DB.alter_table(:items) do
    add_primary_key [:id, :name]
    add_foreign_key [:id, :name], :other_table,
    :key=>[:item_id, :item_name]

  • The AlterTableGenerator now supports unique constraints:

    DB.alter_table(:items) do
    add_unique_constraint [:aaa, :bbb, :ccc], :name => :con3

  • The schema generators now support ON UPDATE (previously, they only
    supported ON DELETE):

    DB.create_table(:items) do
    foreign_key :project_id, :projects, :on_update => :cascade

  • When connecting to a PostgreSQL server version 8.2 and higher,
    Sequel now uses the INSERT … RETURNING … syntax, which should
    speed up row inserts on PostgreSQL. In addition, Sequel Models
    use RETURNING * to speed up model object creation.

  • You can now validate multiple attributes at once. This is useful
    if the combination of two or more attribute values is important,
    such as checking the uniqueness of multiple columns.
    validates_uniqueness_of now supports this directly:

    validates_uniqueness_of [:column1, :column2]

    This protects against the database having multiple rows with the
    same values for both :column1 and :column2. This is different

    validates_uniqueness_of :column1, :column2

    Which checks that the value of column1 is unique in the table, and
    that the value of column2 is unique in the table (which is much
    more restrictive).

Other Improvements

  • Dataset methods insert_sql, delete_sql, and update_sql respect the
    :sql option, allowing you to do things such as:


  • The database adapters (at least MySQL, PostgreSQL, SQLite, and
    JDBC) generally raise Sequel::DatabaseError for database problems,
    making it easier to tell what is a true database error versus an
    error raised by Sequel itself.

  • Sequel uses the async features of ruby-pg so that the entire
    interpreter is not blocked while waiting for the results of

  • Sequel now supports the 2008.08.17 version of ruby-pg.

  • MSSQL support has been improved when using the ODBC and ADO

  • Index names are quoted and creating or dropping indexes.

  • Automatically generated column accessor methods no longer override
    instance methods specified by plugins.

  • Inserting a row with an already specified primary key inside a
    transaction now works correctly when using PostgreSQL.

  • before_save and before_update hooks now work as expected when using

  • count and paginate now work correctly on graphed datasets.

Backwards Compatibility

  • The SQLite adapter now raises Sequel::DatabaseError instead of
    Sequel::Error::InvalidStatement whenever an SQLite3::Exception is
    raised by the SQLite3 driver.

  • Date and DateTime conversions now convert 2 digit years. To revert
    to the previous behavior:

    Sequel.convert_two_digit_years = false

    Note that Ruby 1.8 and 1.9 handle Date parsing differently, so
    there is no backwards compatibility change for Ruby 1.9. However,
    this also means that the MM/DD/YY date syntax commonly used in the
    United States is not always parsed correctly on Ruby 1.9, greatly
    limiting the use of 2 digit year conversion.

  • You can no longer abuse the SQL function syntax for specifying
    database types. For example, you must change:



    :type=>:varchar, :size=>255

If you have any questions, please post on the Google Group.