- A dirty plugin has been added, which saves the initial value of the column
when the column is changed, similar to ActiveModel::Dirty:
artist.name # => 'Foo'
artist.name = 'Bar'
artist.initial_value(:name) # 'Foo'
artist.column_change(:name) # ['Foo', 'Bar']
artist.column_changes # {:name => ['Foo', 'Bar']}
artist.column_changed?(:name) # true
artist.reset_column(:name)
artist.name # => 'Foo'
artist.column_changed?(:name) # false
artist.update(:name=>'Bar')
artist.column_changes # => {}
artist.previous_changes # => {:name=>['Foo', 'Bar']}
- Database#create_table now respects an :as option to create a database based
on the results of a query. The :as option value should either be an SQL
string or a dataset.
DB.create_table(:new_foos, :as=>DB[:foos].where(:new=>true))
- The json_serializer and xml_serializer plugins can now serialize arbitrary
arrays of model objects by passing an :array option to the to_json class
method. This works around an issue in ruby‘s JSON library where
Array#to_json does not pass arguments given to it to the members of the
array.
Artist.to_json(:array=>[Artist[1]], :include=>:albums)
- You can now use the % (modulus) operator in the same way you can use the
bitwise operators in Sequel:
:column.sql_number % 1 # (column % 1)
- On PostgreSQL, you can now provide :only, :cascade, and :restart options to
Dataset#truncate to use ONLY, CASCADE, and RESTART IDENTITY. Additionally,
you can now truncate multiple tables at the same time:
DB.from(:table1, :table2).truncate(:cascade=>true)
- The :index option when creating columns in the schema generator can now
take a hash of index options:
DB.create_table(:foo){Integer :bar, :index=>{:unique=>true}}
- A Database#cache_schema accessor has been added, it can be set to false to
have the Database never cache schema results. This can be useful in Rails
development mode, so that you don‘t need to restart a running server
to have models pick up the new schema.
- Database#log_exception has been added for easier instrumentation. It is
called with the exception and SQL query string for all queries that raise
an exception.
- The Sequel.migration DSL
now has a transaction method that forces transaction use for the given
migration.