ANN: Sequel 2.5.0 Released

J

Jeremy Evans

* 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
improvements:

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
overridden:

DB[:t].set_defaults:)x=>1).insert_sql
# => INSERT INTO t (x) VALUES (1)
DB[:t].set_defaults:)x=>1).insert_sql:)x=>2)
# => INSERT INTO t (x) VALUES (2)
DB[:t].set_defaults:)x=>1).insert_sql:)y=>2)
# => INSERT INTO t (x, y) VALUES (1, 2)
DB[:t].set_overrides:)x=>1).insert_sql:)x=>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], :eek:ther_table, \
:key=>[:item_id, :item_name]
end

DB.alter_table:)items) do
add_primary_key [:id, :name]
add_foreign_key [:id, :name], :eek:ther_table, \
:key=>[:item_id, :item_name]
end

* The AlterTableGenerator now supports unique constraints:

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

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

DB.create_table:)items) do
foreign_key :project_id, :projects, :eek:n_update => :cascade
end

* 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
from:

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:

ds = DB['INSERT INTO t (time) VALUES (CURRENT_TIMESTAMP)']
ds.insert
ds.insert

* 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
queries.

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

* MSSQL support has been improved when using the ODBC and ADO
adapters.

* 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
save_changes.

* 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[255]

to:

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


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

Thanks,
Jeremy

* {Website}[http://sequel.rubyforge.org]
* {Source code}[http://github.com/jeremyevans/sequel]
* {Bug tracking}[http://code.google.com/p/ruby-sequel/issues/list]
* {Google group}[http://groups.google.com/group/sequel-talk]
* {RDoc}[http://sequel.rubyforge.org/rdoc]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top