# ANN: Sequel 0.4.4.2 Released

**URL:** <https://www.ruby-forum.com/t/ann-sequel-0-4-4-2-released/123741>\
**Category:** Ruby\
**Created:** [December 20, 2007, 8:13am UTC](https://www.ruby-forum.com/t/ann-sequel-0-4-4-2-released/123741 "2007-12-20T08:13:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciconia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/71c47a/32.png) [@ciconia](https://www.ruby-forum.com/u/ciconia)\
**Post date:** [December 20, 2007, 8:13am UTC](https://www.ruby-forum.com/t/ann-sequel-0-4-4-2-released/123741/1 "2007-12-20T08:13:15Z")

</div>

Sequel version 0.4.4.2 has just been released. Sequel is a lightweight  
database access and ORM library for Ruby. Sequel provides thread  
safety, connection pooling and a simple and expressive API for  
constructing database queries and table schemas.

This release includes new schema manipulation functionality,  
refactored error classes, compatibility with Ruby 1.9, support for  
iteration inside block filters and a few other minor bug fixes and  
improvements. Here’s a list of the changes:

=== New schema manipulation functionality

Sequel includes a suite of new Database methods for changing the  
database schema. The new methods are #add\_column, #drop\_column,  
#add\_index, #drop\_index, #rename\_column and #set\_column\_type. Usage is  
pretty much self explanatory:

DB.add\_column :items, :category, :text, :default =\> ‘ruby’  
DB.drop\_column :items, :category  
DB.rename\_column :items, :cntr, :counter  
DB.set\_column\_type :items, :counter, :integer  
DB.add\_index :items, :counter  
DB.drop\_index :items, :counter

There is also a new Database#alter\_table method which lets you write  
prettier code when changing the schema:

DB.alter\_table :items do  
DB.add\_column :category, :text, :default =\> ‘ruby’  
DB.drop\_column :category  
DB.rename\_column :cntr, :counter  
DB.set\_column\_type :counter, :integer  
DB.add\_index :counter  
DB.drop\_index :counter  
end

In addition to the table-related methods #create\_table,  
#create\_table!, #drop\_table and #table\_exists? there’s a new  
#rename\_table method:

DB.rename\_table :items, :new\_items

=== Better column definitions

The table creation functionality is improved and provides easier ways  
to define indexes. Indexes on single columns no longer need to be  
defined separately. Instead of this:

DB.create\_table :items  
text :name  
index :name  
end

You can now do this:

DB.create\_table :items  
text :name, :index =\> true  
end

Also, if you want to create a unique index, there’s a new #unique  
method that takes care of that, so instead of this:

DB.create\_table :items  
…  
index [:node\_id, :session\_id], :unique =\> true  
end

You can do this:

DB.create\_table :items  
…  
unique [:node\_id, :session\_id]  
end

Note that if you define a UNIQUE constraint for a column, a unique  
index is implicitly created, e.g.:

DB.create\_table :items  
text :name, :unique =\> true  
end

The schema SQL generation code has also been improved to correctly  
quote field names and default values (according to the adapter used).

=== New Sequel error classes

The old SequelError class has been renamed into Sequel::Error. New  
error classes have been added for specific kinds of errors, all of  
them descendants of Sequel::Error. For example,  
Sequel::Error::InvalidDatabaseScheme is raised when an invalid  
database scheme is specified (duh!).

=== Compatibility with Ruby 1.9

The new release of Sequel is compatible with Ruby 1.9. Be aware though  
that ParseTree is currently not compatible with Ruby 1.9 and therefore  
block filters cannot be used.

=== Support for iteration inside block filters

Sequel now supports iteration inside block filters. This means that  
you can prepare arrays or hashes of values to compare against and  
iterate over them to create query filters. Consider this for example:

# Hash containing minimal values for specific columns in the

dataset.  
thresholds = {  
:group\_a =\> 90,  
:group\_b =\> 60,  
:group\_c =\> 90  
}

In previous releases if you wanted to compare against each value in  
thresholds you had to write it out:

nice = DB[:items].filter do  
:group\_a \>= thresholds[:group\_a]  
:group\_b \>= thresholds[:group\_b]  
:group\_c \>= thresholds[:group\_c]  
end  
nice.sql #=\>  
“SELECT \* FROM specs WHERE ((measure\_a \>= 90) AND (measure\_b \>= 60)  
AND (measure\_c \> 90))”

Now you can simply iterate over the hash:

nice = DB[:items].filter do  
thresholds.each {|k, v| k \>= v}  
end  
nice.sql #=\>  
“SELECT \* FROM specs WHERE ((measure\_a \>= 90) AND (measure\_b \>= 60)  
AND (measure\_c \> 90))”

Nice piece of Ruby magic!

=== Miscellanea

- Changed String#to\_time to raise Error::InvalidValue if Time.parse  
fails. Note: in MySQL it is possible to store invalid timestamp values  
in timestamp columns. If such an invalid timestsamp value is  
encountered, Sequel will raise Sequel::Error::InvalidValue.

- Fixed sync problem in connection\_pool\_spec.

=== More info

Sequel project page:  
[http://code.google.com/p/ruby-sequel](http://code.google.com/p/ruby-sequel)

Sequel documentation:  
[http://sequel.rubyforge.org](http://sequel.rubyforge.org)

Join the Sequel-talk group:  
[http://groups.google.com/group/sequel-talk](http://groups.google.com/group/sequel-talk)

Install the gem:  
sudo gem install sequel

Or check out the source and install manually:  
svn co [http://ruby-sequel.googlecode.com/svn/trunk](http://ruby-sequel.googlecode.com/svn/trunk) sequel  
cd sequel  
rake install
