# ANN: Sequel 2.4.0 Released

**URL:** <https://www.ruby-forum.com/t/ann-sequel-2-4-0-released/145195>\
**Category:** Ruby\
**Created:** [August 6, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/ann-sequel-2-4-0-released/145195 "2008-08-06T19:28:36Z")\
**Posts on this page:** 3\
**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:** [August 6, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/ann-sequel-2-4-0-released/145195/1 "2008-08-06T19:28:36Z")

</div>

- 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, 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, DB2, DBI, Informix, JDBC,  
MySQL, ODBC, OpenBase, Oracle, PostgreSQL and SQLite3.

Sequel 2.4.0 has been released and should be available on the gem  
mirrors. The 2.4.0 release focuses mainly on two major features:

# Prepared Statements/Bound Variables

Sequel now supports prepared statements and bound variables. No  
matter which database you are using, Sequel uses exactly the same API.  
To specify placeholders, you use the :$placeholder syntax:

ds = DB[:items].filter(:name=\>:$n)

To use a bound variable:

ds.call(:select, :n=\>‘Jim’)

This will do the equivalent of selecting records that have the name  
‘Jim’. In addition to :select, you can use :first or :delete. There  
is also support for bound variables when inserting or updating  
records:

ds.call(:update, {:n=\>‘Jim’, :new\_n=\>‘Bob’}, :name=\>:$new\_n)

Which will update all records that have the name ‘Jim’ to have the  
name ‘Bob’.

Prepared statement support is very similar to bound variable support,  
except that the statement is first prepared with a name:

ps = ds.prepare(:select, :select\_by\_name)

It is then called later with the bound arguments to use:

ps.call(:n=\>‘Jim’)  
DB.call(:select\_by\_name, :n=\>‘Jim’) # same as above

For inserting or updating, the hash to use when inserting or updating  
is given to prepare:

ps2 = ds.prepare(:update, :update\_name, :name=\>:$new\_n)  
ps2.call(:n=\>‘Jim’, :new\_n=\>‘Bob’)

There is some level of native support for these features in the  
PostgreSQL, MySQL, SQLite, and JDBC adapters. For other adapters,  
support is emulated, but it shouldn’t be too difficult to add native  
support for them.

For more details see:  
[http://sequel.rubyforge.org/rdoc/files/doc/prepared\_statements\_rdoc.html](http://sequel.rubyforge.org/rdoc/files/doc/prepared_statements_rdoc.html)

# Read-Only Slave/Writable Master and Database Sharding

Sequel now has built in support for master/slave database  
configurations, just by setting an option in Sequel.connect:

DB=Sequel.connect(‘postgres://master\_server/database’,   
:servers=\>{:read\_only=\>{:host=\>‘slave\_server’}})

That will use slave\_server for SELECT queries and master\_server for  
other queries. It’s fairly easy to use multiple slaves or even  
multiple masters, examples are included in the link below.

Sharding support requires some code other than the database  
configuration, but is still fairly simple. For example, to set up  
a 16 shard configuration based on a hex character:

servers = {}  
((‘0’…‘9’).to\_a + (‘a’…‘f’).to\_a).each do |hex|  
servers[hex.to\_sym] = {:host=\>“hash\_host\_#{hex}”}  
end  
DB=Sequel.connect(‘postgres://hash\_host/hashes’, :servers=\>servers)

To set which shard to use for a query, use the Dataset#server method:

DB[:hashes].server(:a).filter(:hash=\>/31337/)

For more details see:  
[http://sequel.rubyforge.org/rdoc/files/doc/sharding\_rdoc.html](http://sequel.rubyforge.org/rdoc/files/doc/sharding_rdoc.html)

# Other Changes

- The [sequel.rubyforge.org](http://sequel.rubyforge.org) website has a new design thanks to boof.  
The online RDoc is now located at [http://sequel.rubyforge.org/rdoc](http://sequel.rubyforge.org/rdoc).

- Support was added for anonymous column names in the ADO adapter.

- Better MSSQL support in the ADO, ODBC, and JDBC adapters. The  
odbc\_mssql adapter has been removed. If you use MSSQL with ODBC,  
please use the odbc adapter with a :db\_type=\>‘mssql’ option.

- The following Sequel::Error exception subclasses were removed:  
InvalidExpression, InvalidFilter, InvalidJoinType, and WorkerStop.

- Documentation was added for the PostgreSQL, MySQL, SQLite, and  
JDBC adapters.

- Various internal interfaces were refactored. For example, if you  
use an adapter not included with Sequel, it probably won’t work  
until you update it to the new internal API.

- Many low level methods (such as Database#transaction), now take  
an optional server argument to indicate which server to use.

- Model plugins that have a DatasetMethods module with non-public  
methods no longer have Model methods created that call those  
methods.

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

Thanks,  
Jeremy

- {Website}[[http://sequel.rubyforge.org](http://sequel.rubyforge.org)]
- {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)]
- {RDoc}[[http://sequel.rubyforge.org/rdoc](http://sequel.rubyforge.org/rdoc)]

---

<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:** [August 6, 2008, 10:05pm UTC](https://www.ruby-forum.com/t/ann-sequel-2-4-0-released/145195/2 "2008-08-06T22:05:31Z")

</div>

Hi Jeremy,

This project sounds pretty sweet and seems to be much more light-weight  
than ActiveRecord. Can you tell me if it handles has\_many :through  
associations, or just many\_to\_many/has\_and\_belongs\_to\_many associations?

–  
Thanks!  
Bryan

---

<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:** [August 6, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/ann-sequel-2-4-0-released/145195/3 "2008-08-06T22:24:42Z")

</div>

Bryan R. wrote:

> Hi Jeremy,
> 
> This project sounds pretty sweet and seems to be much more light-weight  
> than ActiveRecord. Can you tell me if it handles has\_many :through  
> associations, or just many\_to\_many/has\_and\_belongs\_to\_many associations?

It handles has\_many :through associations. See  
[http://sequel.rubyforge.org/rdoc/files/doc/advanced\_associations\_rdoc.html](http://sequel.rubyforge.org/rdoc/files/doc/advanced_associations_rdoc.html)  
for examples.

Jeremy
