# ANN: Sequel 1.5.0 Released

**URL:** <https://www.ruby-forum.com/t/ann-sequel-1-5-0-released/136201>\
**Category:** Ruby\
**Created:** [April 29, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/ann-sequel-1-5-0-released/136201 "2008-04-29T19:40:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerdmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c68b51/32.png) [@nerdmaster](https://www.ruby-forum.com/u/nerdmaster)\
**Post date:** [April 29, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/ann-sequel-1-5-0-released/136201/1 "2008-04-29T19:40:46Z")

</div>

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

DB[:artists].graph(:albums, :artist\_id=\>:id).first

# =\> {:artists=\>{:id=\>artists.id, :name=\>artists.name}, \

# :albums=\>{:id=\>albums.id, :name=\>albums.name,

:artist\_id=\>albums.artist\_id}}

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

DB[:artists].left\_outer\_join(:albums, :artist\_id=\>:id).first

# =\> {:id=\>(albums.id||artists.id),

:name=\>(albums.name||artist.names),   
:artist\_id=\>albums.artist\_id}

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

Artist.graph(Album, :artist\_id=\>:id)

# =\> {:artists=\>#\<Artist…\>, :albums=\>#\<Album…\>}

Models can now eager load via .eager\_graph, which will load all the  
results  
and all associations in a single query. This is necessary if you want  
to  
filter on columns in associated tables. It works exactly the same way  
as  
.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(   
:tracks\_name=\>“Firewire”).all

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,  
:name]).first

# =\> {:artists=\>{:name=\>artists.name}, :albums=\>{:name=\>albums.name}}

You can use eager\_graph with set\_graph\_aliases to have eager loading  
with  
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 # =\> []  
album1.band = band1  
band1.albums # =\> [album1]  
band2.albums # =\> []  
album1.band = band2  
band1.albums # =\> []  
band2.albums # =\> [album1]  
album1.band = band2  
band2.albums # =\> [album1]  
album1.band = nil  
band2.albums # =\> []

# one\_to\_many add\_\* method sets reciprocal association

# one\_to\_many remove\_\* method removes reciprocal association

album1.band # =\> nil  
band1.add\_album(album1)  
album1.band # =\> band1  
band2.add\_album(album1)  
album1.band # =\> band2  
band2.remove\_album(album1)  
album1.band # =\> 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 # =\> []  
tag1.add\_post(post1)  
post1.tags # =\> [tag1]  
tag1.posts # =\> [post1]  
tag1.remove\_post(post1)  
post1.tags # =\> []  
tag1.posts # =\> []  
post1.add\_tag(tag1)  
post1.tags # =\> [tag1]  
tag1.posts # =\> [post1]  
post1.remove\_tag(tag1)  
post1.tags # =\> []  
tag1.posts # =\> []

The MySQL and PostgreSQL adapters now support index types:

index :some\_column, :type =\> :hash # or :spatial, :full\_text, :rtree,  
etc.

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.  
You  
can choose where the messages get sent:

Sequel::Deprecation.deprecation\_message\_stream = STDERR # the default  
Sequel::Deprecation.deprecation\_message\_stream =   
File.new(‘deprecation.txt’, ‘wb’) # A file  
Sequel::Deprecation.deprecation\_message\_stream = nil # ignore the  
messages

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  
messages  
left it in, and we are not aware of anyone using it. Hashes have been  
returned  
by default since Sequel 0.3.

We have also removed the Numeric date/time extensions (e.g. 3.days.ago).  
The  
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  
are  
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  
Informix,  
MySQL, ODBC, ADO, JDBC, Postgres, and SQLite adapters.

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

Thanks,  
Jeremy

- {Project page}[[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/ruby-sequel/)]
- {Source code}[[GitHub - jeremyevans/sequel: Sequel: The Database Toolkit for Ruby](http://github.com/jeremyevans/sequel)]
- {Bug tracking}[[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/ruby-sequel/issues/list)]
- {Google group}[[http://groups.google.com/group/sequel-talk](http://groups.google.com/group/sequel-talk)]
- {RubyForge page}[[http://rubyforge.org/projects/sequel/](http://rubyforge.org/projects/sequel/)]
- {API RDoc}[[http://sequel.rubyforge.org](http://sequel.rubyforge.org)]
