1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
New Features
------------
* The values that are used to insert/update records can now be
scoped similar to how filter expressions can be scoped.
set_defaults is used to set defaults which can be overridden,
and set_overrides is used to set defaults which cannot be
overridden:
DB[:t].set_defaults(:x=>1).insert_sql
# => INSERT INTO t (x) VALUES (1)
DB[:t].set_defaults(:x=>1).insert_sql(:x=>2)
# => INSERT INTO t (x) VALUES (2)
DB[:t].set_defaults(:x=>1).insert_sql(:y=>2)
# => INSERT INTO t (x, y) VALUES (1, 2)
DB[:t].set_overrides(:x=>1).insert_sql(:x=>2)
# => INSERT INTO t (x) VALUES (1)
The difference between set_defaults and set_overrides is that
with set_defaults, the last value takes precedence, while with
set_overrides, the first value takes precedence.
* The schema generators now support creating and altering tables
with composite primary and/or foreign keys:
DB.create_table(:items) do
integer :id
text :name
primary_key [:id, :name]
foreign_key [:id, :name], :other_table, \
:key=>[:item_id, :item_name]
end
DB.alter_table(:items) do
add_primary_key [:id, :name]
add_foreign_key [:id, :name], :other_table, \
:key=>[:item_id, :item_name]
end
* The AlterTableGenerator now supports unique constraints:
DB.alter_table(:items) do
add_unique_constraint [:aaa, :bbb, :ccc], :name => :con3
end
* The schema generators now support ON UPDATE (previously, they only
supported ON DELETE):
DB.create_table(:items) do
foreign_key :project_id, :projects, :on_update => :cascade
end
* When connecting to a PostgreSQL server version 8.2 and higher,
Sequel now uses the INSERT ... RETURNING ... syntax, which should
speed up row inserts on PostgreSQL. In addition, Sequel Models
use RETURNING * to speed up model object creation.
* You can now validate multiple attributes at once. This is useful
if the combination of two or more attribute values is important,
such as checking the uniqueness of multiple columns.
validates_uniqueness_of now supports this directly:
validates_uniqueness_of [:column1, :column2]
This protects against the database having multiple rows with the
same values for both :column1 and :column2. This is different
from:
validates_uniqueness_of :column1, :column2
Which checks that the value of column1 is unique in the table, and
that the value of column2 is unique in the table (which is much
more restrictive).
Other Improvements
------------------
* Dataset methods insert_sql, delete_sql, and update_sql respect the
:sql option, allowing you to do things such as:
ds = DB['INSERT INTO t (time) VALUES (CURRENT_TIMESTAMP)']
ds.insert
ds.insert
* The database adapters (at least MySQL, PostgreSQL, SQLite, and
JDBC) generally raise Sequel::DatabaseError for database problems,
making it easier to tell what is a true database error versus an
error raised by Sequel itself.
* Sequel uses the async features of ruby-pg so that the entire
interpreter is not blocked while waiting for the results of
queries.
* Sequel now supports the 2008.08.17 version of ruby-pg.
* MSSQL support has been improved when using the ODBC and ADO
adapters.
* Index names are quoted and creating or dropping indexes.
* Automatically generated column accessor methods no longer override
instance methods specified by plugins.
* Inserting a row with an already specified primary key inside a
transaction now works correctly when using PostgreSQL.
* before_save and before_update hooks now work as expected when using
save_changes.
* count and paginate now work correctly on graphed datasets.
Backwards Compatibility
-----------------------
* The SQLite adapter now raises Sequel::DatabaseError instead of
Sequel::Error::InvalidStatement whenever an SQLite3::Exception is
raised by the SQLite3 driver.
* Date and DateTime conversions now convert 2 digit years. To revert
to the previous behavior:
Sequel.convert_two_digit_years = false
Note that Ruby 1.8 and 1.9 handle Date parsing differently, so
there is no backwards compatibility change for Ruby 1.9. However,
this also means that the MM/DD/YY date syntax commonly used in the
United States is not always parsed correctly on Ruby 1.9, greatly
limiting the use of 2 digit year conversion.
* You can no longer abuse the SQL function syntax for specifying
database types. For example, you must change:
:type=>:varchar[255]
to:
:type=>:varchar, :size=>255
|