ANN: Sequel 3.9.0 Released


J

Jeremy Evans

Sequel is a lightweight database access toolkit for Ruby.

* 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, stored procedures, 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, Amalgalite, DataObjects,
DB2, DBI, Firebird, Informix, JDBC, MySQL, ODBC, OpenBase, Oracle,
PostgreSQL and SQLite3.

Sequel 3.9.0 has been released and should be available on the gem
mirrors.

New Features
------------

* The ConnectionPool classes were refactored from 2 separate
classes to a 5 class hierarchy, with one main class and 4
subclasses, one for each combination of sharding and threading.

The primary reason for this refactoring is to make it so that
the user doesn't have to pay a performance penalty for sharding
if they aren't using it. A connection pool that supports sharding
is automatically used if the :servers option is used when setting
up the database connection.

In addition, the default connection pool no longer contains
the code to schedule future disconnections of currently allocated
connections. The sharded connection pool must be used if that
feature is desired.

The unsharded connection pools are about 25-30% faster than the
sharded versions.

* An optimistic_locking plugin was added to Sequel::Model. This
plugin implements a simple database-independent locking mechanism
to ensure that concurrent updates do not override changes:

class Person < Sequel::Model
plugin :eek:ptimistic_locking
end
p1 = Person[1]
p2 = Person[1]
# works
p1.update:)name=>'Jim')
# raises Sequel::plugins::OptimisticLocking::Error
p2.update:)name=>'Bob')

In order for this plugin to work, you need to make sure that the
database table has a lock_version column (or other column you name
via the lock_column class level accessor) that defaults to 0.

The optimistic_locking plugin does not work with the
class_table_inheritance plugin.

* Dataset#unused_table_alias was added, which takes a symbol and
returns either that symbol or a new symbol which can be used as
a table alias when joining a table to the dataset. The symbol
returned is guaranteed to not already be used by the dataset:

DB[:test].unused_table_alias:)blah) # => :blah
DB[:test].unused_table_alias:)test) # => :test_0

The use case is when you need to join a table to a dataset, where
the table may already be used inside the dataset, and you want
to generate a unique alias:

ds.join:)table.as(ds.unused_table_alias:)table)), ...)

* The Sequel::ValidationFailed exception now has an errors accessor
which returns the Sequel::Model::Errors instance with the
validation errors. This can be helpful in situations where a
generalized rescue is done where the model object reference is
not available.

* bin/sequel now works without an argument, which is useful for
testing SQL generation (and not much else).

* Support SELECT ... INTO in the MSSQL adapter, using Dataset#into,
which takes a table argument.

* You can now provide your own connection pool class via the
:pool_class option when instantiating the database.

Other Improvements
------------------

* IN/NOT IN constructs with an empty array are now handled properly.

DB[:table].filter:)id=>[]) # IN
DB[:table].exclude:)id=>[]) # NOT IN

Before, the IN construct would mostly work, other than some minor
differences in NULL semantics. However, the NOT IN construct
would not work. Sequel now handles the NOT IN case using an
expression that evaluates to true.

* If using an IN/NOT IN construct with multiple columns and a dataset
argument, where multiple column IN/NOT IN support is emulated, a
separate query is done to get the records, which is then handled
like an array of values. This means that the following type of
query now works on all tested databases:

DB[:table1].filter([:id1, :id2]=>DB[:table2].select:)id1, :id2))

* Schemas and aliases are now handled correctly when eager graphing.

* Implicitly qualified symbols are now handled correctly in update
statements, useful if you are updating a joined dataset and need
to reference a column that appears in multiple tables.

* The active_model plugin has been brought up to date with
activemodel 3.0 beta (though it doesn't work on edge).
Additionally, the active_model plugin now requires active_model
in order to use ActiveModel::Naming.

* In the schema_dumper extension, always include the varchar limit,
even if it is 255 columns (the default). This makes it so that
PostgreSQL will use a varchar(255) column instead of a text column
when restoring a schema dump of a varchar(255) column from another
database.

* You can now load adapters from outside the Sequel lib directory,
now they just need to be in a sequel/adapters directory somewhere
in the LOAD_PATH.

* You can now load extensions from outside the Sequel lib directory
using Sequel.extension. External extensions need to be in a
sequel/extensions directory somewhere in the LOAD_PATH.

* Using bound variables for limit and offset in prepared statements
now works correctly.

* Performance of prepared statements was improved in the native
SQLite adapter.

* The schema_dumper extension now passes the options hash from
dump_*_migration to Database#tables.

* In the single_table_inheritance plugin, qualify the sti_key column
with the table name, so that subclass datasets can safely be joined
to other tables having the same column name.

* In the single_table_inheritance plugin, handle case where the
sti_key value is nil or '' specially, so that those cases
always return an instance of the main model class. This fixes
issues if constantize(nil) returns Object instead of raising
an exception.

* No longer use Date#to_s for literalization, always use ISO8601
format for dates.

* A couple lambdas which were instance_evaled were changed to procs
for ruby 1.9.2 compatibility.

* MSSQL emulated offset support was simplified to only use one
subquery, and made to work correctly on ruby 1.9.

* Emulate multiple column IN/NOT IN on H2, since it doesn't handle
all cases correctly.

* ODBC timestamps are now handled correctly if the database_timezone
is nil.

* ArgumentErrors raised when running queries in the ODBC adapter are
now raised as DatabaseErrors.

* Attempting to use DISTINCT ON on SQLite now raises an error before
sending the query to the database.

* The options hash passed to the database connection method is no
longer modified. However, there may be additional options
present in Database#opts that weren't specified by the options
hash passed to the database connection method.

* Make Dataset#add_graph_aliases handle the case where the dataset
has not yet been graphed.

* You can now provide an SQL::Identifier as a 4th argument to
Dataset#join_table, and unsupported arguments are caught and an
exception is raised.

* The gem specification has been moved out of the Rakefile, so
that the gem can now be built without rake, and works well with
gem build and bundler.

* The Rakefile no longer assumes the current directory is in the
$LOAD_PATH, so it should work correctly on ruby 1.9.2.

* All internal uses of require are now thread safe.

* Empty query parameter keys in connection strings are now ignored
instead of raising an exception.

* The specs were changed so that you can run them in parallel.
Previously there was a race condition in the migration extension
specs.

Backwards Compatibility
-----------------------

* If you plan on using sharding at any point, you now must pass
a :servers option when connecting to the database, even if it is
an empty hash. You can no longer just call Database#add_servers
later.

* The connection_proc and disconnection_proc accessors were removed
from the connection pools, so you can no longer modify the procs
after the connection pool has been instantiated. You must now
provide the connection_proc as the block argument when
instantiating the pool, and the disconnection_proc via the
:disconnection_proc option.

* In the hash passed to Dataset#update, symbol keys with a double
embedded underscore are now considerated as implicit qualifiers,
instead of being used verbatim. If you have a column that includes
a double underscore, you now need to wrap it in an SQL::Identifier
or use a String instead.

* The connection pools no longer convert non-StandardError based
exceptions to RuntimeErrors. Previously, all of the common adapters
turned this feature off, so there is no change for most users.

* Sequel::ConnectionPool is now considered an abstract class and
should not be instantiated directly. Use ConnectionPool.get_pool
to return an instance of the appropriate subclass.

* The Sequel::SingleThreadedPool constant is no longer defined.

* The private Dataset#eager_unique_table_alias method was removed,
use the new public Dataset#unused_table_alias method instead, which
has a slightly different API.

* The private Dataset#eager_graph_qualify_order method was removed,
used Dataset#qualified_expression instead.

* The private Sequel::Model class methods plugin_gem_location and
plugin_gem_location_old have been removed.

* Gems built with the rake tasks now show up in the root directory
instead of the pkg subdirectory, and no tarball package is created.

Other News
----------

* Sequel now has an official blog at http://sequel.heroku.com.

Thanks,
Jeremy

* {Website}[http://sequel.rubyforge.org]
* {Source code}[http://github.com/jeremyevans/sequel]
* {Blog}[http://sequel.heroku.com]
* {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]
 
Ad

Advertisements


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

Top