Skip to content
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


== Sequel: Concise ORM for Ruby

Sequel is an ORM framework for Ruby. Sequel provides thread safety, connection pooling, and a concise DSL for constructing queries and table schemas.

Sequel makes it easy to deal with multiple records without having to break your teeth on SQL.

== Resources

* {Project page}[]
* {Source code}[]
* {Bug tracking}[]
* {Google group}[]
* {RubyForge page}[]

To check out the source code:
  svn co
=== Contact

If you have any comments or suggestions please send an email to ciconia at and I'll get back to you.

== Installation

  sudo gem install sequel

If you don't need to use Sequel models you can just install the sequel_core gem, which includes all database adapters and dataset functionality:

  sudo gem install sequel_core

== Supported Databases

Sequel currently supports:

* ADO (on Windows)
* Informix
* Oracle
* PostgreSQL
* SQLite 3

There are also experimental adapters for DB2, OpenBase and JDBC (on JRuby).

== The Sequel Console

Sequel includes an IRB console for quick'n'dirty access to databases. You can use it like this:

  sequel sqlite:///test.db

You get an IRB session with the database object stored in DB.

== An Introduction

Sequel was designed to take the hassle away from connecting to databases and manipulating them. Sequel deals with all the boring stuff like maintaining connections, formatting SQL correctly and fetching records so you can concentrate on your application.

Sequel uses the concept of datasets to retrieve data. A Dataset object encapsulates an SQL query and supports chainability, letting you fetch data using a convenient Ruby DSL that is both concise and infinitely flexible.

For example, the following one-liner returns the average GDP for the five biggest countries in the middle east region:

  DB[:countries].filter(:region => 'Middle East').reverse_order(:area).limit(5).avg(:GDP)
Which is equivalent to:

  SELECT avg(GDP) FROM countries WHERE region = 'Middle East' ORDER BY area DESC LIMIT 5

Since datasets retrieve records only when needed, they can be stored and later reused. Records are fetched as hashes (they can also be fetched as custom model objects), and are accessed using an Enumerable interface:

  middle_east = DB[:countries].filter(:region => 'Middle East')
  middle_east.order(:name).each {|r| puts r[:name]}
Sequel also offers convenience methods for extracting data from Datasets, such as an extended map method: #=> ['Egypt', 'Greece', 'Israel', ...]
Or getting results as a transposed hash, with one column as key and another as value:

  middle_east.to_hash(:name, :area) #=> {'Israel' => 20000, 'Greece' => 120000, ...}

You can find more information on getting started with Sequel {here}[]
Something went wrong with that request. Please try again.