ANN: Sequel Released

Discussion in 'Ruby' started by Sharon Rosner, Dec 20, 2007.

  1. Sequel version has just been released. Sequel is a lightweight
    database access and ORM library for Ruby. Sequel provides thread
    safety, connection pooling and a simple and expressive API for
    constructing database queries and table schemas.

    This release includes new schema manipulation functionality,
    refactored error classes, compatibility with Ruby 1.9, support for
    iteration inside block filters and a few other minor bug fixes and
    improvements. Here's a list of the changes:

    === New schema manipulation functionality

    Sequel includes a suite of new Database methods for changing the
    database schema. The new methods are #add_column, #drop_column,
    #add_index, #drop_index, #rename_column and #set_column_type. Usage is
    pretty much self explanatory:

    DB.add_column :items, :category, :text, :default => 'ruby'
    DB.drop_column :items, :category
    DB.rename_column :items, :cntr, :counter
    DB.set_column_type :items, :counter, :integer
    DB.add_index :items, :counter
    DB.drop_index :items, :counter

    There is also a new Database#alter_table method which lets you write
    prettier code when changing the schema:

    DB.alter_table :items do
    DB.add_column :category, :text, :default => 'ruby'
    DB.drop_column :category
    DB.rename_column :cntr, :counter
    DB.set_column_type :counter, :integer
    DB.add_index :counter
    DB.drop_index :counter

    In addition to the table-related methods #create_table,
    #create_table!, #drop_table and #table_exists? there's a new
    #rename_table method:

    DB.rename_table :items, :new_items

    === Better column definitions

    The table creation functionality is improved and provides easier ways
    to define indexes. Indexes on single columns no longer need to be
    defined separately. Instead of this:

    DB.create_table :items
    text :name
    index :name

    You can now do this:

    DB.create_table :items
    text :name, :index => true

    Also, if you want to create a unique index, there's a new #unique
    method that takes care of that, so instead of this:

    DB.create_table :items
    index [:node_id, :session_id], :unique => true

    You can do this:

    DB.create_table :items
    unique [:node_id, :session_id]

    Note that if you define a UNIQUE constraint for a column, a unique
    index is implicitly created, e.g.:

    DB.create_table :items
    text :name, :unique => true

    The schema SQL generation code has also been improved to correctly
    quote field names and default values (according to the adapter used).

    === New Sequel error classes

    The old SequelError class has been renamed into Sequel::Error. New
    error classes have been added for specific kinds of errors, all of
    them descendants of Sequel::Error. For example,
    Sequel::Error::InvalidDatabaseScheme is raised when an invalid
    database scheme is specified (duh!).

    === Compatibility with Ruby 1.9

    The new release of Sequel is compatible with Ruby 1.9. Be aware though
    that ParseTree is currently not compatible with Ruby 1.9 and therefore
    block filters cannot be used.

    === Support for iteration inside block filters

    Sequel now supports iteration inside block filters. This means that
    you can prepare arrays or hashes of values to compare against and
    iterate over them to create query filters. Consider this for example:

    # Hash containing minimal values for specific columns in the
    thresholds = {
    :group_a => 90,
    :group_b => 60,
    :group_c => 90

    In previous releases if you wanted to compare against each value in
    thresholds you had to write it out:

    nice = DB[:items].filter do
    :group_a >= thresholds[:group_a]
    :group_b >= thresholds[:group_b]
    :group_c >= thresholds[:group_c]
    nice.sql #=>
    "SELECT * FROM specs WHERE ((measure_a >= 90) AND (measure_b >= 60)
    AND (measure_c > 90))"

    Now you can simply iterate over the hash:

    nice = DB[:items].filter do
    thresholds.each {|k, v| k >= v}
    nice.sql #=>
    "SELECT * FROM specs WHERE ((measure_a >= 90) AND (measure_b >= 60)
    AND (measure_c > 90))"

    Nice piece of Ruby magic!

    === Miscellanea

    * Changed String#to_time to raise Error::InvalidValue if Time.parse
    fails. Note: in MySQL it is possible to store invalid timestamp values
    in timestamp columns. If such an invalid timestsamp value is
    encountered, Sequel will raise Sequel::Error::InvalidValue.

    * Fixed sync problem in connection_pool_spec.

    === More info

    Sequel project page:

    Sequel documentation:

    Join the Sequel-talk group:

    Install the gem:
    sudo gem install sequel

    Or check out the source and install manually:
    svn co sequel
    cd sequel
    rake install
    Sharon Rosner, Dec 20, 2007
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sharon Rosner
    Sharon Rosner
    Apr 16, 2007
  2. Sharon Rosner

    ANN: Sequel 0.0.20 Released

    Sharon Rosner, Apr 18, 2007, in forum: Ruby
    Sharon Rosner
    Apr 18, 2007
  3. Sharon Rosner

    ANN: Sequel 0.1.0 Released

    Sharon Rosner, Apr 22, 2007, in forum: Ruby
    Sharon Rosner
    Apr 22, 2007
  4. Sharon Rosner

    ANN: Sequel 0.1.2 Released

    Sharon Rosner, May 19, 2007, in forum: Ruby
    Sharon Rosner
    May 19, 2007
  5. Sharon Rosner
    Sharon Rosner
    May 20, 2007

Share This Page