sequel 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +51 -1
- data/README.rdoc +2 -2
- data/Rakefile +2 -2
- data/doc/advanced_associations.rdoc +6 -18
- data/doc/release_notes/1.0.txt +38 -0
- data/doc/release_notes/1.1.txt +143 -0
- data/doc/release_notes/1.3.txt +101 -0
- data/doc/release_notes/1.4.0.txt +53 -0
- data/doc/release_notes/1.5.0.txt +155 -0
- data/doc/release_notes/2.0.0.txt +298 -0
- data/doc/release_notes/2.1.0.txt +271 -0
- data/doc/release_notes/2.10.0.txt +328 -0
- data/doc/release_notes/2.11.0.txt +215 -0
- data/doc/release_notes/2.2.0.txt +253 -0
- data/doc/release_notes/2.3.0.txt +88 -0
- data/doc/release_notes/2.4.0.txt +106 -0
- data/doc/release_notes/2.5.0.txt +137 -0
- data/doc/release_notes/2.6.0.txt +157 -0
- data/doc/release_notes/2.7.0.txt +166 -0
- data/doc/release_notes/2.8.0.txt +171 -0
- data/doc/release_notes/2.9.0.txt +97 -0
- data/lib/sequel_core/adapters/ado.rb +3 -0
- data/lib/sequel_core/adapters/db2.rb +0 -11
- data/lib/sequel_core/adapters/dbi.rb +0 -11
- data/lib/sequel_core/adapters/do.rb +0 -12
- data/lib/sequel_core/adapters/firebird.rb +21 -16
- data/lib/sequel_core/adapters/informix.rb +1 -11
- data/lib/sequel_core/adapters/jdbc.rb +1 -13
- data/lib/sequel_core/adapters/jdbc/h2.rb +3 -11
- data/lib/sequel_core/adapters/jdbc/mysql.rb +0 -17
- data/lib/sequel_core/adapters/jdbc/postgresql.rb +3 -15
- data/lib/sequel_core/adapters/mysql.rb +31 -27
- data/lib/sequel_core/adapters/odbc.rb +34 -28
- data/lib/sequel_core/adapters/openbase.rb +0 -11
- data/lib/sequel_core/adapters/oracle.rb +11 -9
- data/lib/sequel_core/adapters/postgres.rb +14 -17
- data/lib/sequel_core/adapters/shared/mssql.rb +6 -15
- data/lib/sequel_core/adapters/shared/mysql.rb +29 -14
- data/lib/sequel_core/adapters/shared/oracle.rb +4 -0
- data/lib/sequel_core/adapters/shared/postgres.rb +30 -35
- data/lib/sequel_core/adapters/shared/progress.rb +4 -0
- data/lib/sequel_core/adapters/shared/sqlite.rb +73 -13
- data/lib/sequel_core/adapters/sqlite.rb +8 -18
- data/lib/sequel_core/adapters/utils/date_format.rb +21 -0
- data/lib/sequel_core/{dataset → adapters/utils}/stored_procedures.rb +0 -0
- data/lib/sequel_core/{dataset → adapters/utils}/unsupported.rb +0 -0
- data/lib/sequel_core/core_ext.rb +1 -1
- data/lib/sequel_core/core_sql.rb +9 -4
- data/lib/sequel_core/database.rb +63 -62
- data/lib/sequel_core/dataset.rb +9 -4
- data/lib/sequel_core/dataset/convenience.rb +10 -9
- data/lib/sequel_core/dataset/prepared_statements.rb +1 -1
- data/lib/sequel_core/dataset/sql.rb +130 -36
- data/lib/sequel_core/schema/sql.rb +2 -2
- data/lib/sequel_core/sql.rb +44 -51
- data/lib/sequel_core/version.rb +1 -1
- data/lib/sequel_model/associations.rb +25 -17
- data/lib/sequel_model/base.rb +35 -7
- data/lib/sequel_model/caching.rb +1 -6
- data/lib/sequel_model/record.rb +23 -5
- data/lib/sequel_model/validations.rb +20 -5
- data/spec/adapters/firebird_spec.rb +6 -1
- data/spec/adapters/mysql_spec.rb +12 -0
- data/spec/adapters/postgres_spec.rb +2 -2
- data/spec/adapters/sqlite_spec.rb +81 -2
- data/spec/integration/dataset_test.rb +2 -2
- data/spec/integration/type_test.rb +12 -2
- data/spec/sequel_core/core_sql_spec.rb +46 -12
- data/spec/sequel_core/database_spec.rb +24 -12
- data/spec/sequel_core/dataset_spec.rb +82 -32
- data/spec/sequel_core/schema_spec.rb +16 -0
- data/spec/sequel_model/associations_spec.rb +89 -0
- data/spec/sequel_model/base_spec.rb +66 -0
- data/spec/sequel_model/eager_loading_spec.rb +32 -0
- data/spec/sequel_model/record_spec.rb +9 -9
- data/spec/sequel_model/spec_helper.rb +3 -0
- data/spec/sequel_model/validations_spec.rb +63 -3
- metadata +41 -4
@@ -0,0 +1,271 @@
|
|
1
|
+
Model Improvements
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* one_to_many/many_to_many associations now support a :limit option,
|
5
|
+
adding a limit/offset to the records returned. This was possible
|
6
|
+
before using a block, so it is just added for convenience.
|
7
|
+
|
8
|
+
* Associations now support a :read_only option, which doesn't create
|
9
|
+
methods that modify the database.
|
10
|
+
|
11
|
+
* Associations now support a :graph_select option, which allows
|
12
|
+
specifying the columns of associated models to include when using
|
13
|
+
eager_graph.
|
14
|
+
|
15
|
+
* one_to_many associations now have a :one_to_one option. When used
|
16
|
+
it creates a getter and setter method similar to many_to_one. This
|
17
|
+
fills the same role as ActiveRecord's has_one, but it is
|
18
|
+
implemented as a couple of convenience methods over one_to_many, so
|
19
|
+
it still requires that you specify the association name as a
|
20
|
+
plural.
|
21
|
+
|
22
|
+
* Model datasets now have to_hash augmented so that it can be called
|
23
|
+
without any arguments, in which case it yields an identity map (a
|
24
|
+
hash with keys being primary key values and values being model
|
25
|
+
instances).
|
26
|
+
|
27
|
+
* The Model.set_sti_key method was added, for easily setting up
|
28
|
+
single table inheritance. It should be called only in the parent
|
29
|
+
class.
|
30
|
+
|
31
|
+
* Calls to def_dataset_method with a block are now cached and
|
32
|
+
reapplied to the new dataset if set_dataset is called afterward,
|
33
|
+
or in a subclass.
|
34
|
+
|
35
|
+
* All validation methods can now be made conditional via an :if
|
36
|
+
option, which takes either a symbol (which specifies an instance
|
37
|
+
method) or a proc (which is instance_evaled).
|
38
|
+
|
39
|
+
* Model#set and Model#update have been added back, they are now
|
40
|
+
aliases of #set_with_params and #update_with_params.
|
41
|
+
|
42
|
+
* Models now have set_only/set_except/update_only/update_except
|
43
|
+
instance methods that take a hash (like you would provide to
|
44
|
+
set or update) and additional arguments specifying which columns
|
45
|
+
to allow or disallow.
|
46
|
+
|
47
|
+
* Models now have a set_allowed_columns and set_restricted_columns
|
48
|
+
methods, which operate similarly to ActiveRecord's attr_accessible
|
49
|
+
and attr_protected. It is recommend that you use the set_only or
|
50
|
+
update_only instead of these methods, though. You can ignore the
|
51
|
+
allowed or restricted columns by using #set_all or #update_all.
|
52
|
+
|
53
|
+
* The primary key column(s) is restricted by default. To allow it to
|
54
|
+
be set via new/set/update, use:
|
55
|
+
|
56
|
+
Sequel::Model.unrestrict_primary_key # Global
|
57
|
+
Artist.unrestrict_primary_key # Per Class
|
58
|
+
|
59
|
+
* It is now easy to override the one_to_many/many_to_many association
|
60
|
+
methods that modify the database (add_/remove_/remove_all_), as
|
61
|
+
they have been broken into two methods, one that handles the
|
62
|
+
caching features and a private one (prepended with an _) that
|
63
|
+
handles the database changes (and which you can easily override
|
64
|
+
without worrying about the caching).
|
65
|
+
|
66
|
+
Table Joining
|
67
|
+
-------------
|
68
|
+
|
69
|
+
Dataset#join_table got a nice overhaul. You can now use any join
|
70
|
+
type your database allows:
|
71
|
+
|
72
|
+
DB[:artist].join_table(:natural, :albums)
|
73
|
+
DB[:numbers].join_table(:cross, :numbers)
|
74
|
+
|
75
|
+
You can now specify the conditions as
|
76
|
+
|
77
|
+
* String: "a.b = c.d" # ON a.b = c.d
|
78
|
+
* Expression :x < :y # ON x < y
|
79
|
+
* Array of Symbols: [:x, :y, :z] # USING (x, y, z)
|
80
|
+
* nil # no conditions, used for NATURAL or CROSS joins
|
81
|
+
|
82
|
+
Dataset#join_table also takes a block that yields three arguments:
|
83
|
+
|
84
|
+
* join_table_alias - The alias/name of the table currently being
|
85
|
+
joined
|
86
|
+
* last_join_table_alias - The alias name of the last table joined
|
87
|
+
(if there was one) or the first FROM table (if not).
|
88
|
+
* joins - An array of JoinClause objects for all previous joins in
|
89
|
+
the query.
|
90
|
+
|
91
|
+
Using the block you can specify conditions for complex joins without
|
92
|
+
needing to know in advance what table aliases will be used.
|
93
|
+
|
94
|
+
Expanded SQL Syntax Support
|
95
|
+
---------------------------
|
96
|
+
|
97
|
+
SQL Case statements are now supported directly using hashes or
|
98
|
+
arrays:
|
99
|
+
|
100
|
+
{:x > 1 => 1}.case(0)
|
101
|
+
# CASE WHEN x > 1 THEN 1 ELSE 0 END
|
102
|
+
[[{:x=>1}, 0], [:x < 1, 1], [:x > 1, 2]].case(-1)
|
103
|
+
# CASE WHEN x = 1 THEN 0 WHEN x < 1 THEN 1 WHEN x > 1 THEN 2
|
104
|
+
ELSE -1 END
|
105
|
+
|
106
|
+
You should use an array instead of a hash for multiple conditions
|
107
|
+
unless all conditions are orthogonal.
|
108
|
+
|
109
|
+
The SQL extract function has special syntax:
|
110
|
+
|
111
|
+
EXTRACT(day FROM date)
|
112
|
+
|
113
|
+
This syntax is now supported via the following ruby code:
|
114
|
+
|
115
|
+
:date.extract(:day)
|
116
|
+
|
117
|
+
Other Notable Changes
|
118
|
+
---------------------
|
119
|
+
|
120
|
+
* The sequel command line tool can now run migrations. The -m
|
121
|
+
option specifies the directory holding the migration files,
|
122
|
+
and the -M options specifies the version to which to migrate.
|
123
|
+
|
124
|
+
* The PostgreSQL adapter supports nested transactions/savepoints.
|
125
|
+
|
126
|
+
* The schema parser now understands decimal fields, and will
|
127
|
+
typecast to BigDecimal.
|
128
|
+
|
129
|
+
* PostgreSQL's numeric type is now recognized and returned as
|
130
|
+
BigDecimal.
|
131
|
+
|
132
|
+
* HAVING now comes before ORDER BY, which most databases seem to
|
133
|
+
prefer. If your database wants HAVING after ORDER BY, please
|
134
|
+
let us know.
|
135
|
+
|
136
|
+
* Symbol#qualify now exists, to specify the table name for a given
|
137
|
+
symbol, similar to the use of #as to specify an alias. This is
|
138
|
+
mainly helpful in conjuction with the #join_table block, as that
|
139
|
+
provides the table aliases to use to qualify the columns inside
|
140
|
+
the block.
|
141
|
+
|
142
|
+
* BitwiseMethods (&, |, ^, ~, <<, >>) have been added to the
|
143
|
+
NumericExpression class, so you can do the following:
|
144
|
+
|
145
|
+
(x + 1) ^ 10 # SQL: (x + 1) ^ 10
|
146
|
+
~(x + 1) # SQL: ~(x + 1)
|
147
|
+
|
148
|
+
Usually, &, |, and ~ operate in a logical manner, but for
|
149
|
+
NumericExpressions, they take on their usual bitwise meaning,
|
150
|
+
since logical operations only make sense for booleans.
|
151
|
+
|
152
|
+
* #cast_numeric and #cast_string exist for Symbols, Strings, and
|
153
|
+
other Sequel Expressions, which return the results casted and
|
154
|
+
wrapped in either NumericExpression or StringExpression, so you
|
155
|
+
can use the BitwiseMethods (&, |, ^, ~, <<, >>) or
|
156
|
+
StringConcatenationMethods (+) directly.
|
157
|
+
|
158
|
+
# Dataset#to_hash can take only one argument, in which case it uses
|
159
|
+
that argument to specify the key, and uses the entire hash for the
|
160
|
+
value.
|
161
|
+
|
162
|
+
# Dataset#graph can now take an array of columns to select from the
|
163
|
+
joined table via the :select option.
|
164
|
+
|
165
|
+
# Dataset#filter and similar methods now combine the block and
|
166
|
+
regular argument conditions if both are given, instead of ignoring
|
167
|
+
the regular argument conditions.
|
168
|
+
|
169
|
+
# Dataset#filter(false) can now be used to make sure that no records
|
170
|
+
are returned. Dataset#filter(true) also works, but it's a no-op.
|
171
|
+
Before, these raised errors.
|
172
|
+
|
173
|
+
# Dataset#count does a subquery for a dataset using DISTINCT, since
|
174
|
+
the otherwise it would yield a count for the query without
|
175
|
+
DISTINCT.
|
176
|
+
|
177
|
+
ParseTree Support Officially Deprecated
|
178
|
+
---------------------------------------
|
179
|
+
|
180
|
+
The support for ParseTree-based block filters has officially been
|
181
|
+
deprecated and will be removed in Sequel 2.2. To use the
|
182
|
+
expression filters (which don't require ParseTree) inside blocks,
|
183
|
+
use:
|
184
|
+
|
185
|
+
SEQUEL_NO_PARSE_TREE = true
|
186
|
+
require 'sequel'
|
187
|
+
# OR
|
188
|
+
require 'sequel'
|
189
|
+
Sequel.use_parse_tree = false
|
190
|
+
|
191
|
+
This is the default if ParseTree cannot be loaded. If ParseTree
|
192
|
+
can be loaded, it remains the default, in order not to immediately
|
193
|
+
break existing code.
|
194
|
+
|
195
|
+
With this set, you can use the expression filters inside of blocks:
|
196
|
+
|
197
|
+
dataset.filter{((:x + 1) & 10 < :y) & :z}
|
198
|
+
|
199
|
+
That doesn't gain you all that much, but there are some methods
|
200
|
+
that feed block arguments into filter, such as the following:
|
201
|
+
|
202
|
+
dataset.first(5){((:x + 1) & 10 < :y) & :z}
|
203
|
+
|
204
|
+
Which will get you the first 5 records matching the condition.
|
205
|
+
|
206
|
+
Backwards Incompatible Changes
|
207
|
+
------------------------------
|
208
|
+
|
209
|
+
* To change the datetime classe used from Time to DateTime, you
|
210
|
+
now use:
|
211
|
+
|
212
|
+
Sequel.datetime_class = DateTime # instead of Sequel.time_class
|
213
|
+
|
214
|
+
* Models now raise errors if you try to access a missing or
|
215
|
+
restricted method via new/set/update, instead of just silently
|
216
|
+
skipping that parameter. To get the old behavior:
|
217
|
+
|
218
|
+
Sequel::Model.strict_param_setting = false
|
219
|
+
|
220
|
+
* The association_dataset method now takes into account the :eager
|
221
|
+
option and the block argument, where it didn't before. It also
|
222
|
+
takes into account the new :limit option.
|
223
|
+
|
224
|
+
* Association methods now raise errors in most cases if the model
|
225
|
+
doesn't have a valid primary key.
|
226
|
+
|
227
|
+
* Dataset#join_table used to allow a symbol as a conditions argument
|
228
|
+
as a shortcut for a hash:
|
229
|
+
|
230
|
+
DB[:artist].join(:albums, :artist_id)
|
231
|
+
# ON albums.artist_id = artists.id
|
232
|
+
|
233
|
+
With the changes to #join_table, this no longer works. It would
|
234
|
+
now be interpreted as a boolean column:
|
235
|
+
|
236
|
+
DB[:artist].join(:albums, :artist_id)
|
237
|
+
# ON artists.id
|
238
|
+
|
239
|
+
Use the following slightly longer version for the old behavior:
|
240
|
+
|
241
|
+
DB[:artist].join(:albums, :artist_id=>:id)
|
242
|
+
# ON albums.artist_id = artists.id
|
243
|
+
|
244
|
+
* MySQL users need to be careful when upgrading, the following code
|
245
|
+
will once again cause an error:
|
246
|
+
|
247
|
+
DB[:artists].each{|artist| DB[:albums].each{|album| ...}}
|
248
|
+
|
249
|
+
To fix it, change the code to:
|
250
|
+
|
251
|
+
DB[:artists].all{|artist| DB[:albums].each{|album| ...}}
|
252
|
+
|
253
|
+
The issue is the MySQL adapter doesn't release the database
|
254
|
+
connection while running each, and the second call to each gets the
|
255
|
+
same database connection (while the other query is still running),
|
256
|
+
because it is in the same thread. Using #all for the outside query
|
257
|
+
ensures that the database connection is released before the block is
|
258
|
+
called.
|
259
|
+
|
260
|
+
The reason for this change was that the workaround provided for
|
261
|
+
MySQL could potentially cause issues with transactions for all
|
262
|
+
adapters.
|
263
|
+
|
264
|
+
* String#asc and String#desc are no longer defined, as ordering on a
|
265
|
+
plain string column should be a no-op. They are still defined
|
266
|
+
on LiteralStrings.
|
267
|
+
|
268
|
+
* You can no longer abuse the SQL::Function syntax to use a table
|
269
|
+
alias with specified columns (e.g. :table[:col1, :col2, :col3])
|
270
|
+
or to cast to types (e.g. :x.cast_as(:varchar[20])). Use a
|
271
|
+
LiteralString in both cases.
|
@@ -0,0 +1,328 @@
|
|
1
|
+
New Supported Adapters and Databases
|
2
|
+
------------------------------------
|
3
|
+
|
4
|
+
* A DataObjects adapter was added that supports PostgreSQL,
|
5
|
+
MySQL, and SQLite. DataObjects is the underlying database
|
6
|
+
library used by DataMapper, and has potential performance
|
7
|
+
advantages by doing all typecasting in C.
|
8
|
+
|
9
|
+
* A Firebird Adapter was added, it requires the modified Ruby
|
10
|
+
Fb adapter found at http://github.com/wishdev/fb.
|
11
|
+
|
12
|
+
* An H2 JDBC subadapter was added, based on the code used in JotBot.
|
13
|
+
H2 is an embeddable Java database, and may be preferable to using
|
14
|
+
SQLite on JDBC because SQLite requires native code.
|
15
|
+
|
16
|
+
New Core Features
|
17
|
+
-----------------
|
18
|
+
|
19
|
+
* Sequel now has database independent migrations. Before, column
|
20
|
+
types in migrations were not translated per database, so it was
|
21
|
+
difficult to set up a migration that worked on multiple databases.
|
22
|
+
Sequel now accepts ruby classes as database types, in addition to
|
23
|
+
symbols and strings. If a ruby class is used, it is translated
|
24
|
+
to the most appropriate database type. Here is an example using
|
25
|
+
all supported classes (with Sequel's default database type):
|
26
|
+
|
27
|
+
DB.create_table(:cats) do
|
28
|
+
primary_key :id, :type=>Integer # integer
|
29
|
+
String :a # varchar(255)
|
30
|
+
column :b, File # blob
|
31
|
+
Fixnum :c # integer
|
32
|
+
foreign_key :d, :other_table, :type=>Bignum # bigint
|
33
|
+
Float :e # double precision
|
34
|
+
BigDecimal :f # numeric
|
35
|
+
Date :g # date
|
36
|
+
DateTime :h # timestamp
|
37
|
+
Time :i # timestamp
|
38
|
+
Numeric :j # numeric
|
39
|
+
TrueClass :k # boolean
|
40
|
+
FalseClass :l # boolean
|
41
|
+
end
|
42
|
+
|
43
|
+
Type translations were tested on the PostgreSQL, MySQL, SQLite,
|
44
|
+
and H2 databases. The default translations should work OK for
|
45
|
+
most databases, but there will probably be a type or two that
|
46
|
+
doesn't work. Please send in a patch if Sequel uses a column type
|
47
|
+
that doesn't work on your database.
|
48
|
+
|
49
|
+
Note that existing migrations still work fine, in most cases. If
|
50
|
+
you were using strings or symbols for types before, they should
|
51
|
+
still work. See the Backwards Compatibility section below for
|
52
|
+
details.
|
53
|
+
|
54
|
+
Also note that this doesn't relate solely to migrations, as any
|
55
|
+
database schema modification method that accepts types will
|
56
|
+
accept one of the above classes.
|
57
|
+
|
58
|
+
* A ton of internal work was done to better support databases that
|
59
|
+
fold unqouted identifiers to uppercase (which is the SQL standard).
|
60
|
+
Sequel now allows you to set a method to call on identifiers going
|
61
|
+
both into and out of the database. The default is to downcase
|
62
|
+
identifiers coming out, and upcase identifiers going in, though
|
63
|
+
this is overridden by the PostgreSQL, MySQL, and SQLite adapters
|
64
|
+
to not do anything (since they fold to lowercase by default).
|
65
|
+
|
66
|
+
The settings are called identifier_input_method and
|
67
|
+
identifier_output_method, and like most Sequel settings, they can
|
68
|
+
be set globally, per database, or per dataset:
|
69
|
+
|
70
|
+
# Global (use uppercase in ruby and lowercase in the database)
|
71
|
+
Sequel.identifier_input_method = :downcase
|
72
|
+
Sequel.identifier_output_method = :upcase
|
73
|
+
# Per Database (use camelized names in the database, and
|
74
|
+
# underscored names in ruby)
|
75
|
+
DB.identifier_input_method = :camelize
|
76
|
+
DB.identifier_output_method = :underscore
|
77
|
+
# Per Dataset (obfuscate your database columns!)
|
78
|
+
class String; def rot_13; tr('A-Za-z', 'N-ZA-Mn-za-m') end end
|
79
|
+
ds = DB[:table]
|
80
|
+
ds.identifier_input_method = :rot_13
|
81
|
+
ds.identifier_output_method = :rot_13
|
82
|
+
|
83
|
+
* Schema parsing support was added to the JDBC adapter, using the
|
84
|
+
JDBC metadata methods. This means that models that use the
|
85
|
+
JDBC adapter will typecast data in their column setters and
|
86
|
+
automatically select the correct primary key column(s). This is
|
87
|
+
currently the only adapter that supports schema parsing when using
|
88
|
+
an MSSQL or Oracle database.
|
89
|
+
|
90
|
+
* Database#create_table now takes options, which you can use to
|
91
|
+
specify a MySQL engine, charset, and/or collation. You can also
|
92
|
+
set a default engine, charset, and collation for MySQL to use:
|
93
|
+
|
94
|
+
Sequel::MySQL.default_engine = 'InnoDB'
|
95
|
+
Sequel::MySQL.default_charset = 'utf8'
|
96
|
+
Sequel::MySQL.default_collate = 'utf8'
|
97
|
+
|
98
|
+
The defaults will be used if the options are not provided. If a
|
99
|
+
default engine is set, you can specify :engine=>nil to not use it
|
100
|
+
(same goes for charset and collate).
|
101
|
+
|
102
|
+
* The Sequel::DatabaseConnectionError exception class was added. It
|
103
|
+
is raised by the connection pool if there is an error attempting
|
104
|
+
to instantiate a database connection. Also, if the adapter returns
|
105
|
+
nil instead of raising an error for faulty connection parameters,
|
106
|
+
DatabaseConnectionError will be raised immediately, instead of the
|
107
|
+
connection pool busy waiting until if gives up with a
|
108
|
+
PoolTimeoutError.
|
109
|
+
|
110
|
+
* Database#tables is now supported on the JDBC adapter, returning
|
111
|
+
an Array of table name symbols.
|
112
|
+
|
113
|
+
* Sequel now converts the following Java types returned by the JDBC
|
114
|
+
adapter into ruby types: Java::JavaSQL::Timestamp,
|
115
|
+
Java::JavaSQL::Time, Java::JavaSQL::Date,
|
116
|
+
Java::JavaMath::BigDecimal, and Java::JavaIo::BufferedReader.
|
117
|
+
|
118
|
+
* When using the PostgreSQL adapter with the postgres-pr driver,
|
119
|
+
Sequel will use a custom string escaping routine unless
|
120
|
+
force_standard_strings = false. This means that using Sequel's
|
121
|
+
defaults, postgres-pr will correctly escape strings now.
|
122
|
+
|
123
|
+
* The SQLite adapter now returns float, real, and double precision
|
124
|
+
columns as Floats.
|
125
|
+
|
126
|
+
* The SQLite adapter logs beginning, committing, and rolling back
|
127
|
+
transactions.
|
128
|
+
|
129
|
+
* Sequel now has an internal version (before, the only way to tell
|
130
|
+
the version was to look at the gem being used). It is accessible
|
131
|
+
at Sequel.version.
|
132
|
+
|
133
|
+
New Model Features
|
134
|
+
------------------
|
135
|
+
|
136
|
+
* A new validates_not_string validation was added for Sequel Models.
|
137
|
+
It is intended to be used with the raise_on_typecast_failure =
|
138
|
+
false setting. In this case, for a non-string database column,
|
139
|
+
if there is a string value when the record is going to be
|
140
|
+
saved, it is due to the fact that Sequel was not able to typecast
|
141
|
+
the given data correctly (so it is almost certainly not valid).
|
142
|
+
This should make Sequel easier to use with web applications.
|
143
|
+
|
144
|
+
* An :allow_missing validation option was added to all standard
|
145
|
+
validations. This option skips the validation if the attribute
|
146
|
+
is not in the object's values. It is different from :allow_nil,
|
147
|
+
which will skip the value if it is present but nil in the values.
|
148
|
+
The intended use case for this option is when the database provides
|
149
|
+
a good default. If the attribute is not present in values, the
|
150
|
+
database will use its default. If the attribute is present in
|
151
|
+
the values but equals nil, Sequel will attempt to insert it into
|
152
|
+
the database as a NULL value, instead of using the database's
|
153
|
+
default. If you don't want Sequel to insert a NULL value in the
|
154
|
+
database, but you want the database to provide the default, this
|
155
|
+
is the option to use.
|
156
|
+
|
157
|
+
* validates_each now accepts :allow_nil and :allow_blank options,
|
158
|
+
so it is easier to create custom validations with the same options
|
159
|
+
as the standard validations.
|
160
|
+
|
161
|
+
* Before_* hooks now run in the reverse order that they were added.
|
162
|
+
The purpose of hooks is to wrap existing functionality, and making
|
163
|
+
later before_* hooks run before previous before_* hooks is the
|
164
|
+
correct behavior.
|
165
|
+
|
166
|
+
* You can now add you own hook types, via Model.add_hook_type. This
|
167
|
+
is intended for plugin use. All of the standard hooks are now
|
168
|
+
implemented using this method.
|
169
|
+
|
170
|
+
* The value of new? in a after_save hook now reflects the
|
171
|
+
previous state of the model (so true for a create and false for an
|
172
|
+
update), instead of always being false. This makes it easier
|
173
|
+
to have a complex after_save hook that still needs to
|
174
|
+
differentiate between a newly created record and an updated record,
|
175
|
+
without having to add separate after_create and after_update
|
176
|
+
hooks.
|
177
|
+
|
178
|
+
* The value of changed_columns in an after_update hook now reflects
|
179
|
+
the value before the update occurred, instead of usually being
|
180
|
+
empty. Previously, to have this functionality, you generally had
|
181
|
+
to save the value to an instance variable in a before_update hook
|
182
|
+
so you could reference it in the after_update hook.
|
183
|
+
|
184
|
+
Other Improvements
|
185
|
+
------------------
|
186
|
+
|
187
|
+
* Sequel now longer overwrites the following Symbol instance methods
|
188
|
+
when running on ruby 1.9: [], <, <=, >, and >=. One of Sequel's
|
189
|
+
principals is that it does not override methods defined by ruby,
|
190
|
+
and now that ruby 1.9 defines the above methods on Symbol, Sequel
|
191
|
+
shouldn't be overwriting them.
|
192
|
+
|
193
|
+
Sequel already provides a way to work around this issue when
|
194
|
+
another library adds the same methods to Symbol that Sequel does.
|
195
|
+
For example, you need to change the following:
|
196
|
+
|
197
|
+
dataset.filter(:number > 1)
|
198
|
+
dataset.filter(:number >= 2)
|
199
|
+
dataset.filter(:name < 'M')
|
200
|
+
dataset.filter(:name <= 'I')
|
201
|
+
dataset.filter(:is_bool[:x])
|
202
|
+
|
203
|
+
To:
|
204
|
+
|
205
|
+
dataset.filter{|o| o.number > 1}
|
206
|
+
dataset.filter{|o| o.number >= 2}
|
207
|
+
dataset.filter{|o| o.name < 'M'}
|
208
|
+
dataset.filter{|o| o.name <= 'I'}
|
209
|
+
dataset.filter{|o| o.is_bool(:x)}
|
210
|
+
|
211
|
+
The argument provided to the block is a Sequel::SQL::VirtualRow.
|
212
|
+
This class uses method_missing so that any methods called on it
|
213
|
+
return Sequel::SQL::Identifiers (if no arguments are provided)
|
214
|
+
or Sequel::SQL::Function (if arguments are provided).
|
215
|
+
|
216
|
+
If you were using one of the above symbol methods outside of a
|
217
|
+
filter, you can to call sql_string, sql_number, or sql_function
|
218
|
+
on the symbol. So the following would also work:
|
219
|
+
|
220
|
+
dataset.filter(:number.sql_number > 1)
|
221
|
+
dataset.filter(:number.sql_number >= 2)
|
222
|
+
dataset.filter(:name.sql_string < 'M')
|
223
|
+
dataset.filter(:name.sql_number <= 'I')
|
224
|
+
dataset.filter(:is_bool.sql_function(:x))
|
225
|
+
|
226
|
+
Using the block argument makes for a nicer API, though, so I
|
227
|
+
recommend using it when possible.
|
228
|
+
|
229
|
+
Note that if you are running ruby 1.8 or jruby without the --1.9
|
230
|
+
flag, you don't need to worry. If you are running ruby 1.9 or
|
231
|
+
jruby --1.9, or you plan to at some point in the future, you
|
232
|
+
should inspect your code for existing uses of these methods.
|
233
|
+
Here are a couple command lines that should find most uses:
|
234
|
+
|
235
|
+
# Find :symbol[]
|
236
|
+
egrep -nr ':['\''"]?[a-zA-Z_0-9]*['\''"]?\[' *
|
237
|
+
# Find :symbol (<|>|<=|>=)
|
238
|
+
egrep -nr '[^:]:['\''"]?[a-zA-Z_0-9]*['\''"]? *[<>]=?' *
|
239
|
+
|
240
|
+
* Database#quote_identifiers now affects future schema modifications
|
241
|
+
when using the database. Previous, it only affected future
|
242
|
+
schema modifications if a schema modification method had not yet
|
243
|
+
been called.
|
244
|
+
|
245
|
+
* Literalization of Times and DateTimes is now correct when using the
|
246
|
+
MySQL JDBC subadapter.
|
247
|
+
|
248
|
+
* Literalization of Blobs is now correct when using the PostgreSQL
|
249
|
+
JDBC subadapter.
|
250
|
+
|
251
|
+
* Index and table names are quoted when creating indices in the
|
252
|
+
PostgreSQL adapter.
|
253
|
+
|
254
|
+
* Dataset#delete was changed in the SQLite adapter to add a
|
255
|
+
where clause that is always true, instead of doing an explicit
|
256
|
+
count first and the deleting. This is simpler, though it
|
257
|
+
could potentially have performance implications.
|
258
|
+
|
259
|
+
* The sequel command line tool now supports symbol keys and unnested
|
260
|
+
hashes in YAML files, so it should work with Merb's database.yml.
|
261
|
+
It also includes the error class in the case of an error.
|
262
|
+
|
263
|
+
* The integration type tests were greatly expanded. Generally,
|
264
|
+
running the integration tests is a good way to determine how well
|
265
|
+
your database is supported.
|
266
|
+
|
267
|
+
* Dataset#quote_identifier now returns LiteralStrings as-is, instead
|
268
|
+
of treating them as regular strings.
|
269
|
+
|
270
|
+
* Sequel no longer modifies the MySQL::Result class when using the
|
271
|
+
MySQL adapter.
|
272
|
+
|
273
|
+
Backwards Compatibilty
|
274
|
+
----------------------
|
275
|
+
|
276
|
+
* If you were previously using a database that returned uppercase
|
277
|
+
identifiers, it will probably return lowercase identifiers by
|
278
|
+
default now. To get back the old behavior:
|
279
|
+
|
280
|
+
DB.identifier_output_method = nil
|
281
|
+
|
282
|
+
* The module hierarchy under Sequel::SQL has changed. Now,
|
283
|
+
modules do not include other modules, and the following modules
|
284
|
+
were removed since they would have been empty after removing
|
285
|
+
the modules they included: Sequel::SQL::SpecificExpressionMethods
|
286
|
+
and Sequel::SQL::GenericExpressionMethods.
|
287
|
+
|
288
|
+
* Sequel no longer assumes the public schema by default when
|
289
|
+
connecting to PostgreSQL. You can still set the default
|
290
|
+
schema to use (even to public).
|
291
|
+
|
292
|
+
* The ability to load schema information for all tables at once
|
293
|
+
was removed from the PostgreSQL adapter. While it worked, it had
|
294
|
+
some issues, and it was difficult to keep it working when some
|
295
|
+
new features were used. This ability wasn't exposed to the user,
|
296
|
+
and was purely an optimization. If you have any code like:
|
297
|
+
|
298
|
+
DB.schema
|
299
|
+
|
300
|
+
by itself after the Database object was instantiated, you should
|
301
|
+
remove it.
|
302
|
+
|
303
|
+
* The Database#primary_key API changed in the PostgreSQL shared
|
304
|
+
adapter, it now accepts an options hash with :server and :conn keys
|
305
|
+
instead of a server symbol. Also, quite a few private Database
|
306
|
+
instance methods changed, as well as some constants in the
|
307
|
+
AdapterMethods.
|
308
|
+
|
309
|
+
* It is possible that some migrations will break, though it is
|
310
|
+
unlikely. If you were using any of the classes mentioned above
|
311
|
+
as a method inside a migration, it might be broken. However,
|
312
|
+
since String, Float, and Integer wouldn't have worked as methods
|
313
|
+
before, it is unlikely that anyone used this.
|
314
|
+
|
315
|
+
* The meaning of #String, #Integer, and #Float inside
|
316
|
+
Sequel::SQL::Generator (i.e. inside a Database#create_table
|
317
|
+
block) has changed. Before, these used to call private Kernel
|
318
|
+
methods, now, they set up columns with the appropriate database
|
319
|
+
type.
|
320
|
+
|
321
|
+
* The Database#lowercase method in the DBI adapter was removed,
|
322
|
+
as its use case is now met by the identifier_output_method support.
|
323
|
+
|
324
|
+
* Database#uri is now aliased explicitly via a real method, to
|
325
|
+
allow for easier subclassing.
|
326
|
+
|
327
|
+
* You can no longer pass nil as the second argument to
|
328
|
+
Database#create_table.
|