Path: | doc/release_notes/3.29.0.txt |
Last Update: | Tue Sep 25 21:08:33 +0000 2012 |
DB = Sequel.mock(:fetch=>{:id=>1}, :numrows=>2, :autoid=>3) DB[:items].all # => [{:id => 1}] DB[:items].insert # => 3 DB[:items].insert # => 4 DB[:items].delete # => 2 DB[:items].update(:id=>2) # => 2 DB.sqls # => ['SELECT ...', 'INSERT ...', ...]
In addition to being useful in the specs, the mock adapter is also used if you use bin/sequel without a database argument, which makes it much easier to play around with Sequel on the command line without being tied to a real database.
Sequel.transaction([DB1, DB2]){...} # similar to: DB1.transaction{DB2.transaction{...}}
You can combine this with the :rollback => :always option to easily use multiple databases in the same test suite and make sure that changes are rolled back on all of them.
# Dataset of tracks from albums with name < 'M' # by artists with name > 'M' Artist.filter(:name > 'M').albums.filter(:name < 'M').tracks # SELECT * FROM tracks # WHERE (tracks.album_id IN ( # SELECT albums.id FROM albums # WHERE ((albums.artist_id IN ( # SELECT artists.id FROM artists # WHERE (name > 'M'))) # AND (name < 'M'))))
Using this feature allows you to override any dataset method and call super, similar to how Sequel::Model plugins work. The method takes either a module:
Sequel.extension :columns_introspection DB.extend_datasets(Sequel::ColumnsIntrospection)
or a block that it uses to create an anonymous module:
DB.extend_datasets do # Always select from table.* instead of * def from(*tables) ds = super if !@opts[:select] || @opts[:select].empty? ds = ds.select_all(*tables) end ds end end
DB << "UPDATE foo SET bar_id = NULL" << "DROP TABLE bars" DB[:foo] << {:bar_id=>0} << DB[:bars].select(:id)
# process 1 DB.listen('foo') do |ev, pid, payload| ev # => 'foo' notify_pid # => some Integer payload # => 'bar' end # process 2 DB.notify('foo', :payload=>'bar')
The prepared_statements plugin now checks this setting and works correctly on adapters that set it to true, such as oracle.
The rcte_tree plugin now checks this setting an works correctly on databases that set it to true, such as Oracle and HSQLDB.
Model.call was added, and now .load is just an alias for .call. This allows you to make the model dataset‘s row_proc the model itself, instead of needing a separate block, which improves performance.
While Model.load used to call .new (and therefore initialize), Model.call uses .allocate/set_values/after_initialize for speed. This saves a method call or two, and skips setting the @new instance variable.
Model.dataset = DB[:table].select(:column1, :column2) Model.select_more(:column3).first.column3
Additionally, @new is no longer set to false for objects retieved from the database, since setting it to false hurts performance. Model#new? still returns true or false, so this only affects you if you are checking the instance variables directly.
dataset.map(:foo) # to dataset.map{|r| r[:foo]} dataset.to_hash(:foo, :bar) # to h = {} dataset.each{|r| h[r[:foo]] = r[:bar]} h
# Case sensitive DB[:foos].where(:name.like('bar%')) # Case insensitive DB[:foos].where(:name.ilike('bar%'))
Sequel now sets the case_sensitive_like PRAGMA to true by default on SQLite. To set it to false instead, pass the :case_sensitive_like=>false option to the database when creating it.