ANN: Sequel 1.5.0 Released


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 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 1.5.0 has been released and should be available on the gem
mirrors. 1.5.0 has the following exciting new features:

You can now graph a dataset and have the result split into component

DB[:artists].graph:)albums, :artist_id=>:id).first
# => {:artists=>{:id=>, :name=>}, \
# :albums=>{:id=>, :name=>,

This aliases columns if necessary so they don't stomp on each other,
is what usually happens if you just join the tables:

DB[:artists].left_outer_join:)albums, :artist_id=>:id).first
# => {:id=>(||,
:name=>(||artist.names), \

Models can use graph as well, in which case the values will be model

Artist.graph(Album, :artist_id=>:id)
# => {:artists=>#<Artist...>, :albums=>#<Album...>}

Models can now eager load via .eager_graph, which will load all the
and all associations in a single query. This is necessary if you want
filter on columns in associated tables. It works exactly the same way
eager, and supports cascading of associations as well:

# Artist.one_to_many :albums
# Album.one_to_many :tracks
# Track.many_to_one :genre
Artist.eager_graph:)albums=>{:tracks=>:genre}).filter( \

This will give you all artists have have an album with a track named
"Firewire", and calling .albums on one of those artists will only return
albums that have a track named "Firewire", and calling .tracks on one of
those albums will return only the track(s) named "Firewire".

You can use set_graph_aliases to select specific columns:

DB[:artists].graph:)albums, :artist_id=>:id).set_graph_aliases( \
:artist_name=>[:artists, :name], :album_name=>[:albums,
# => {:artists=>{:name=>}, :albums=>{:name=>}}

You can use eager_graph with set_graph_aliases to have eager loading
control over the SELECT clause.

All associations now update their reciprocal associations whenever the
association methods are used, so you don't need to refresh the
association or model to have the reciprocal association updated:

Album.many_to_one :band
Band.one_to_many :albums

# Note that all of these associations are cached,
# so after the first access there are no additional
# database queries to fetch associated records.

# many_to_one setter adds to reciprocal association
band1.albums # => [] = band1
band1.albums # => [album1]
band2.albums # => [] = band2
band1.albums # => []
band2.albums # => [album1] = band2
band2.albums # => [album1] = nil
band2.albums # => []

# one_to_many add_* method sets reciprocal association
# one_to_many remove_* method removes reciprocal association # => nil
band1.add_album(album1) # => band1
band2.add_album(album1) # => band2
band2.remove_album(album1) # => nil

Post.many_to_many :tags
Tag.many_to_many :posts

# many_to_many add_* method adds to reciprocal association
# many_to_many remove_* method removes from reciprocal association
post1.tags # => []
tag1.posts # => []
post1.tags # => [tag1]
tag1.posts # => [post1]
post1.tags # => []
tag1.posts # => []
post1.tags # => [tag1]
tag1.posts # => [post1]
post1.tags # => []
tag1.posts # => []

The MySQL and PostgreSQL adapters now support index types:

index :some_column, :type => :hash # or :spatial, :full_text, :rtree,

Starting in Sequel 1.5.0, some methods are deprecated. These methods
will be
removed in Sequel 2.0.0. The deprecation framework is fairly flexible.
can choose where the messages get sent:

Sequel::Deprecation.deprecation_message_stream = STDERR # the default
Sequel::Deprecation.deprecation_message_stream = \'deprecation.txt', 'wb') # A file
Sequel::Deprecation.deprecation_message_stream = nil # ignore the

You can even have all deprecation messages accompanied by a traceback,
so you
can see exactly where in your code you are using a deprecated method:

Sequel::Deprecation.print_tracebacks = true

All deprecation methods come with an message telling you what
alternative code
will work.

In addition to deprecating some methods, we removed the ability to have
arrays returned instead of hashes. The array code still had debugging
left it in, and we are not aware of anyone using it. Hashes have been
by default since Sequel 0.3.

We have also removed the Numeric date/time extensions (e.g. 3.days.ago).
existing extensions were incomplete, better ones are provided elsewhere,
and the extensions were not really related to Sequel's purpose.

Sequel no longer depends on ParseTree, RubyInline, or ruby2ruby. They
still required to use the block filters. Sequel's only gem dependency
is on
the tiny metaid.

Sequel 1.5.0 has fixes for 12 tracker issues, including fixes to the
MySQL, ODBC, ADO, JDBC, Postgres, and SQLite adapters.

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


* {Project page}[]
* {Source code}[]
* {Bug tracking}[]
* {Google group}[]
* {RubyForge page}[]
* {API 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