Sequel version 0.4.3 has just been released. This release includes
numerous improvements and bug fixes. Here's a list of the changes:
=== Database-related
* Added Database#add_index method, letting you add indexes without
having to create a schema:
DB.add_index(:items, :node_id)
* Added support for inline index definition. Instead of adding an
index statement for each column you want to create, you can just add
an index option:
DB.create_table(:items) do
text :name, :index => true
end
* Added Database#create_table! method for forcibly creating a table.
This method will drop the table (if it exists) before creating it
again.
* Added Database#create_view, #create_or_replace_view and #drop_view
methods. You can supply either a dataset or an SQL as the source for
the view. For example:
DB.create_view(:my_view, 'SELECT x FROM y')
DB.create_view(:another_view, DB[:items].where {!:item_sucks})
Also implemented are Dataset#create_view and #create_or_replace_view
convenience methods.
DB[:items].where(:active => true).create_view(:active_items)
=== Dataset-related
* Dataset#update can now accept blocks or plain strings. You can now
supply a custom string with assignment expressions:
DB[:items].update("x = 1")
#=> "UPDATE items SET x = 1"
You can also now supply a block to update:
DB[:items].update do
:x << 1
:y << 2
end
#=> "UPDATE items SET x = 1, y = 2"
This is very useful if you need to do stuff like incrementing a
counter column or using a custom SQL expression:
DB[:items].update {:count << :count + 1}
#=> "UPDATE items SET count = count + 1"
DB[:items].update {:featured << :price < 100}
#=> "UPDATE items SET featured = price < 100"
* Added support for subscript access using Symbol#| operator. If you
use array types in your tables you now have an easy way of accessing
array items:
DB[:items].select((:year|1).as(:value)).sql
#=> "SELECT year[1] AS value FROM items"
ds = DB[:items].where {:month|1 > 0}
ds.update {(:year|1) << (:year|1) + (:month|1)}
#=> "UPDATE items SET year[1] = (year[1] + month[1]) WHERE (month[1]
0)"
You can also access items in multi-dimensional arrays:
DB[:items].where {:bits|1|2|3 > 0}.sql
#=> "SELECT * FROM items WHERE (bits[1, 2, 3] > 0)"
=== Model-related
* Added Model.create_with_params method that filters the given
parameters accordring to the model's columns (thanks Aman Gupta). This
method was added by to request from users of Merb and Ramaze that
wanted a simple way to create a model instance from request
parameters. The method filters out any parameters that do not have
corresponding columns in the underlying dataset.
=== Miscellaneous
* Fixed Model. to raise for boolean argument (#97).
* Added error reporting for filtering on comparison not in a block
(thanks Jim Morris).
* Fixed Dataset#count to work properly with datasets with fixed SQL
(when using #fetch).
* Refactored and fixed Dataset#reverse_order to work with field
quoting (thanks Christian).
* Fixed problem with field quoting in insert statements.
* Changed sequelizer code to silently fail on any error when requiring
parsetree and ruby2ruby.
* Keep DRY by re-using Model#= from method_missing.
* Added Model.fetch alias for DB.fetch.set_model(Model).
=== More info
Sequel project page:
<Google Code Archive - Long-term storage for Google Code Project Hosting.;
Sequel documentation:
<http://sequel.rubyforge.org>
Join the Sequel-talk group:
<http://groups.google.com/group/sequel-talk>
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