# ANN: Sequel 0.1.8 Released

**URL:** <https://www.ruby-forum.com/t/ann-sequel-0-1-8-released/108977>\
**Category:** Ruby\
**Created:** [July 10, 2007, 7:34am UTC](https://www.ruby-forum.com/t/ann-sequel-0-1-8-released/108977 "2007-07-10T07:34:36Z")\
**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:** [July 10, 2007, 7:34am UTC](https://www.ruby-forum.com/t/ann-sequel-0-1-8-released/108977/1 "2007-07-10T07:34:36Z")

</div>

Sequel version 0.1.8 has just been released. This release is focused  
on substantial refactoring of the Dataset class, mainly in order to  
simplify individual adapter implementations. Also included in this  
release are several bug fixes and some new features.

Important: I did my best to ensure that all adapters will work  
correctly, but I can only test two on my setup: sqlite and postgres.  
So if you use other adapters please let me know if you run into  
trouble. Worst case just remove version 0.1.8 and install version  
0.1.7.

Following is a discussion of the main changes:

# Support for polymorphic models

Datasets can now provide support for polymorphic models by  
instantiating model instances based on a value in a specific column.  
For example:

addresses = DB[:addresses]  
addresses.set\_model(:kind, 1 =\> User, 2 =\> Company)

This is pretty much self-explanatory. The dataset will lookup the  
value of the :kind column for each row and instantiate the respective  
model class. You can also specify a default model class:

address.set\_model(:kind, 1 =\> User, 2 =\> Company, nil =\>  
Addressable)

In order to specify a single model to use, just call the #set\_model  
method with a single class:

addresses = DB[:addresses]  
addresses.set\_model(Address)

# Retrieving the columns in a dataset

The Dataset class includes a new #columns method which lets you  
retrieve the column names in the result set in the correct order:

DB[:items].columns #=\>  
[:id, :name, :price]

The Dataset#print method has also been updated to automatically use  
this method to determine the order of columns in the printed table.

# SQLite Pragmas

The SQLite adapter includes several methods to dynamically control  
database behavior. You can programatically set the auto\_vacuum,  
synchronous and temp\_store pragmas, e.g.:

DB.auto\_vacuum = :full # one of :none, :full, :incremental  
DB.synchronous = :off # one of :off, :normal, :full  
DB.temp\_store = :memory # one of :default, :file, :memory

You can also set and retrieve other pragma values:

DB.pragma\_get(:encoding)  
DB.pragma\_set(:encoding, ‘UTF-8’)

# Postgresql EXPLAIN ANALYZE

The postgres adapter now includes a Postgres::Dataset#analyze method  
to further analyze query performance. Here’s some sample output:

Session.producers.sql #=\>  
“SELECT \* FROM sessions WHERE NOT (mount\_path IS NULL)”  
puts Session.producers.analyze

# output

Seq Scan on sessions (cost=0.00…617.76 rows=18483 width=152)  
(actual time=34.454…34.454 rows=0 loops=1)  
Filter: (NOT (mount\_path IS NULL))  
Total runtime: 34.551 ms

Also, Postgres::Dataset#explain was broken and is now fixed.

# Simplified and standardized Dataset adapter interface

Writing a Sequel adapter is now much easier. A Dataset implementation  
should only override 4 methods: fetch\_rows, insert, update and delete.

# More specs

Sequel is now at 95% code coverage on the specs. There is also a new  
sqlite adapter spec. Adapter specs can be tested by running rake  
spec\_all.

# Miscellaneous

- Fixed Postgres::Dataset#explain.

- Renamed Dataset#hash\_column to Dataset#to\_hash.

- Various code tweaks.

======================

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
