From: Sharon Rosner Date: 2007-12-20T16:12:36+09:00 Subject: ANN: Sequel 0.4.4.2 Released Sequel version 0.4.4.2 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 end 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 end You can now do this: DB.create_table :items text :name, :index => true end 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 end You can do this: DB.create_table :items ... unique [:node_id, :session_id] end 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 end 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 dataset. 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] end 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} end 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 http://ruby-sequel.googlecode.com/svn/trunk sequel cd sequel rake install