Path: | doc/release_notes/3.11.0.txt |
Last Update: | Tue Feb 01 14:04:26 +0000 2011 |
# The default - Log all successful queries at INFO level DB.log_warn_duration = nil # Log all successful queries at WARN level DB.log_warn_duration = 0 # Log successful queries that take the database more than half a # second at WARN level, other successful queries at INFO level DB.log_warn_duration = 0.5
All adapters included with Sequel have been modified to support the new logging API. The previous API is still available, so any external adapters should still work, though switching to the new logging API is encouraged.
DB.create_table(:as){primary_key :id} class A < Sequel::Model; end a = A.create # delete object from database a.delete a.require_modification = false a.save # no error! a.delete # no error! a.require_modification = true a.save # Sequel::NoExistingObject exception raised a.delete # Sequel::NoExistingObject exception raised
Like many other Sequel::Model settings, this can be set on a global, per class, and per instance level:
Sequel::Model.require_modification = false # global Album.require_modification = true # class album.require_modification = false # instance
class Item < Sequel::Model plugin :instance_filters end # These are two separate objects that represent the same # database row. i1 = Item.first(:id=>1, :delete_allowed=>false) i2 = Item.first(:id=>1, :delete_allowed=>false) # Add an instance filter to the object. This filter is in effect # until the object is successfully updated or deleted. i1.instance_filter(:delete_allowed=>true) # Attempting to delete the object where the filter doesn't # match any rows raises an error. i1.delete # raises Sequel::Error # The other object that represents the same row has no # instance filters, and can be updated normally. i2.update(:delete_allowed=>true) # Even though the filter is now still in effect, since the # database row has been updated to allow deleting, # delete now works. i1.delete
This is useful for customizations you want set on every connection that Sequel doesn‘t already support. For example, on PostgreSQL if you wanted to set the schema search_path on every connection:
DB = Sequel.postgres('dbname', :after_connect=>(proc do |conn| conn.execute('SET search_path TO schema1,schema2') end))
ds = DB[:a] # SELECT * FROM items ds.select_more({:id=>DB[:b].select(:a_id)}.as(:in_b)) # SELECT id IN (SELECT a_id FROM b) AS in_b FROM a ds.select_append({:id=>DB[:b].select(:a_id)}.as(:in_b)) # SELECT *, id IN (SELECT a_id FROM b) AS in_b FROM a
h = {} h[:name] = name if name h[:number] = number if number ds = ds.filter(h)
Before, this would raise an error if both name and number were nil.