ANN: Sequel 0.3 Released

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

  1. Sequel version 0.3 has just been released. This release includes
    support for retrieving tuples as arrays instead of hashes, a more
    mature model implementation with support for composite primary keys
    and caching, and a new way for quickly retrieving records, as well as
    many other minor improvements and bug fixes.

    Sequel is a lightweight ORM library for Ruby. Sequel provides thread
    safety, connection pooling and a simple and expressive API for
    constructing database queries and table schemas.

    Following is a discussion of the major changes:

    === Retrieving tuples as arrays

    By default Sequel represents record tuples using Ruby hashes. Some
    people, however, have expressed a desire to retrieve records as
    arrays, in order to have a predictable column order. Sequel version
    0.3 can provide array tuples, and also extends them with key access
    (in a similar fashion to Ara Howard's arrayfields). To use array
    tuples you should add the following line to your code:


    Working with the returned array tuples is basically the same as
    working with hash tuples:

    DB[:items].first.class #=> Array
    # key access lets you treat arrays as if they were hashes
    DB[:items].each {|r| p r[:name]}
    DB[:items].first.each_pair {|k, v| p [k, v]}

    === Sequel models: composite primary keys, caching

    The model implementation has been largely refactored, documented and
    spec'd out and is now much more mature. Sequel models now support
    composite primary keys, which are useful especially for auxiliary

    class Attribute < Sequel::Model:)attributes)
    set_primary_key [:node_id, :kind]

    class Node < Sequel::Model:)nodes)
    def attribute(kind)
    Attribute[pkey, kind]

    Also new in this release is support for caching using memcached:

    require 'memcache'
    CACHE = 'localhost:11211', :namespace => 'dbstuff'

    class Attribute < Sequel::Model:)attributes)
    set_primary_key [:node_id, :kind]
    set_cache CACHE, :ttl => 3600

    Attribute[1, 2] # database hit
    Attribute[1, 2] # cache hit

    === New API for retrieving records with plain SQL

    While Sequel is great for expressing queries in Ruby, sometimes you
    just want to retrieve records with plain SQL. The new Database#fetch
    method lets you do that:

    DB.fetch('select * from items') {|r| p r}

    The #fetch method will return an enumerator if a block is not given,
    letting you do stuff like:

    names = DB.fetch('select * from items').map {|r| r[:name]}
    records = DB.fetch('select * from items').to_a

    You can also create parameterized queries and enjoy protection from
    SQL injection:

    DB.fetch('select * from items where name like ?', client_name).to_a

    The Database#[] method has also been modified to act as shortcut to
    #fetch if a string is given:

    DB['select * from items'].each {|r| p r}

    === Other improvements and bug fixes

    * Added Database#logger= method for setting the database logger

    * Implemented Database#disconnect method for all adapters.

    * Changed Database#<< to strip comments and whitespace only when an
    array is given.

    * Added support for old and new decimal types in MySQL adapter, and
    updated MYSQL_TYPES with MySQL 5.0 constants (#72).

    * Fixed bug in postgres adapter where a LiteralString would be
    literalized as a regular String.

    * Fixed SQLite insert with subquery (#68).

    * Rewrote SQLite::Database#transaction to use sqlite3-ruby library
    implementation of transactions.

    * Model hooks can now be prepended or appended in order to change
    order of execution.

    * Enhanced Model.find method to accept block filters.

    * Added stock transforms to Dataset#transform. Refactored

    * Enhanced Dataset#first to accept a filter block. Model#find can also
    now accept a filter block.

    * Changed Dataset#join methods to correctly literalize values in join
    conditions (#70).

    * Fixed #filter with ranges to correctly literalize field names (#69).

    * Added Dataset#to_csv method.

    * Extended Dataset#from to auto alias sub-queries and accept hash for
    aliasing tables.

    * Changed Schema::Generator#primary_key to accept calls with the type
    argument omitted.

    === 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, Oct 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