sequel 3.9.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +56 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/doc/advanced_associations.rdoc +7 -10
- data/doc/release_notes/3.10.0.txt +286 -0
- data/lib/sequel/adapters/do/mysql.rb +4 -0
- data/lib/sequel/adapters/jdbc.rb +5 -0
- data/lib/sequel/adapters/jdbc/as400.rb +58 -0
- data/lib/sequel/adapters/jdbc/oracle.rb +30 -0
- data/lib/sequel/adapters/shared/mssql.rb +23 -9
- data/lib/sequel/adapters/shared/mysql.rb +12 -1
- data/lib/sequel/adapters/shared/postgres.rb +7 -18
- data/lib/sequel/adapters/shared/sqlite.rb +5 -0
- data/lib/sequel/adapters/sqlite.rb +5 -0
- data/lib/sequel/connection_pool/single.rb +3 -3
- data/lib/sequel/database.rb +3 -2
- data/lib/sequel/dataset.rb +6 -5
- data/lib/sequel/dataset/convenience.rb +3 -3
- data/lib/sequel/dataset/query.rb +13 -0
- data/lib/sequel/dataset/sql.rb +31 -1
- data/lib/sequel/extensions/schema_dumper.rb +3 -3
- data/lib/sequel/model.rb +8 -6
- data/lib/sequel/model/associations.rb +144 -102
- data/lib/sequel/model/base.rb +21 -1
- data/lib/sequel/model/plugins.rb +3 -1
- data/lib/sequel/plugins/association_dependencies.rb +14 -7
- data/lib/sequel/plugins/caching.rb +4 -0
- data/lib/sequel/plugins/composition.rb +138 -0
- data/lib/sequel/plugins/identity_map.rb +2 -2
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +3 -2
- data/lib/sequel/plugins/rcte_tree.rb +281 -0
- data/lib/sequel/plugins/typecast_on_load.rb +16 -5
- data/lib/sequel/sql.rb +18 -1
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +4 -0
- data/spec/adapters/mysql_spec.rb +4 -0
- data/spec/adapters/postgres_spec.rb +55 -5
- data/spec/core/database_spec.rb +5 -3
- data/spec/core/dataset_spec.rb +86 -15
- data/spec/core/expression_filters_spec.rb +23 -6
- data/spec/extensions/association_dependencies_spec.rb +24 -5
- data/spec/extensions/association_proxies_spec.rb +3 -0
- data/spec/extensions/composition_spec.rb +194 -0
- data/spec/extensions/identity_map_spec.rb +16 -0
- data/spec/extensions/nested_attributes_spec.rb +44 -1
- data/spec/extensions/rcte_tree_spec.rb +205 -0
- data/spec/extensions/schema_dumper_spec.rb +6 -0
- data/spec/extensions/spec_helper.rb +6 -0
- data/spec/extensions/typecast_on_load_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +5 -5
- data/spec/integration/dataset_test.rb +13 -9
- data/spec/integration/eager_loader_test.rb +56 -1
- data/spec/integration/model_test.rb +8 -0
- data/spec/integration/plugin_test.rb +270 -0
- data/spec/integration/schema_test.rb +1 -1
- data/spec/model/associations_spec.rb +541 -118
- data/spec/model/eager_loading_spec.rb +24 -3
- data/spec/model/record_spec.rb +34 -0
- metadata +9 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,59 @@
|
|
1
|
+
=== 3.10.0 (2010-04-02)
|
2
|
+
|
3
|
+
* Make one_to_one setter and *_to_many remove_all methods apply the association options (jeremyevans)
|
4
|
+
|
5
|
+
* Make nested_attributes plugin handle invalid many_to_one associations better (john_firebaugh)
|
6
|
+
|
7
|
+
* Remove private methods from Sequel::BasicObject on ruby 1.8 (i.e. most Kernel methods) (jeremyevans)
|
8
|
+
|
9
|
+
* Add Sequel::BasicObject.remove_methods!, useful on 1.8 if libraries required after Sequel add methods to Object (jeremyevans)
|
10
|
+
|
11
|
+
* Change Sequel.connect with a block to return the block's value (jonas11235)
|
12
|
+
|
13
|
+
* Add an rcte_tree plugin, which uses recursive common table expressions for loading trees stored as adjacency lists (jeremyevans)
|
14
|
+
|
15
|
+
* Make typecast_on_load plugin also typecast when refreshing the object (either explicitly or implicitly after creation) (jeremyevans)
|
16
|
+
|
17
|
+
* Fix schema parsing and dumping of tinyint columns when connecting to MySQL via the do adapter (ricardochimal)
|
18
|
+
|
19
|
+
* Fix transactions when connecting to Oracle via JDBC (jeremyevans)
|
20
|
+
|
21
|
+
* Fix plugin loading when plugin module name is the same as an already defined top level constant (jeremyevans)
|
22
|
+
|
23
|
+
* Add an AS400 JDBC subadapter (need jt400.jar in classpath) (jeremyevans, bhauff)
|
24
|
+
|
25
|
+
* Fix the emulated MSSQL offset support when core extensions are not used (jeremyevans)
|
26
|
+
|
27
|
+
* Make Sequel::BasicObject work correctly on Rubinius (kronos)
|
28
|
+
|
29
|
+
* Add the :eager_loader_key option to associations, useful for custom eager loaders (jeremyevans)
|
30
|
+
|
31
|
+
* Dataset#group_and_count no longer orders by the count (jeremyevans)
|
32
|
+
|
33
|
+
* Fix Dataset#limit on MSSQL 2000 (jeremyevans)
|
34
|
+
|
35
|
+
* Support eagerly load nested associations when lazily loading *_to_one associations using the :eager option (jeremyevans)
|
36
|
+
|
37
|
+
* Fix the one_to_one setter to work with a nil argument (jeremyevans)
|
38
|
+
|
39
|
+
* Cache one_to_one associations like many_to_one associations instead of one_to_many associations (jeremyevans)
|
40
|
+
|
41
|
+
* Use the singular form for one_to_one association names instead of the plural form (john_firebaugh)
|
42
|
+
|
43
|
+
* Add real one_to_one associations, using the :one_to_one option of one_to_many is now an error (jeremyevans)
|
44
|
+
|
45
|
+
* Add Model#lock! which uses Dataset#for_update to lock model rows (jeremyevans)
|
46
|
+
|
47
|
+
* Add Dataset#for_update as a standard dataset method (jeremyevans)
|
48
|
+
|
49
|
+
* Add composition plugin, simlar to ActiveRecord's composed_of (jeremyevans)
|
50
|
+
|
51
|
+
* Combine multiple complex expressions for simpler SQL and object tree (jeremyevans)
|
52
|
+
|
53
|
+
* Add Dataset#first_source_table, for the unaliased version of the table for the first source (jeremyevans)
|
54
|
+
|
55
|
+
* Raise a more explicit error if attempting to use the sqlite adapter with sqlite3 instead of sqlite3-ruby (jeremyevans)
|
56
|
+
|
1
57
|
=== 3.9.0 (2010-03-04)
|
2
58
|
|
3
59
|
* Allow loading adapters and extensions from outside of the Sequel lib directory (jeremyevans)
|
data/README.rdoc
CHANGED
@@ -112,7 +112,7 @@ The connection URL can also include such stuff as the user name and password:
|
|
112
112
|
You can also specify optional parameters, such as the connection pool size, or loggers for logging SQL queries:
|
113
113
|
|
114
114
|
DB = Sequel.connect("postgres://postgres:postgres@localhost/my_db",
|
115
|
-
:max_connections => 10, :
|
115
|
+
:max_connections => 10, :logger => Logger.new('log/db.log'))
|
116
116
|
|
117
117
|
You can specify a block to connect, which will disconnect from the database after it completes:
|
118
118
|
|
data/Rakefile
CHANGED
@@ -59,7 +59,7 @@ task :website_rdoc=>[:website_rdoc_main, :website_rdoc_adapters, :website_rdoc_p
|
|
59
59
|
Rake::RDocTask.new(:website_rdoc_main) do |rdoc|
|
60
60
|
rdoc.rdoc_dir = "www/public/rdoc"
|
61
61
|
rdoc.options += RDOC_OPTS
|
62
|
-
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG COPYING lib/*.rb lib/sequel/*.rb lib/sequel/{dataset,database,model}/*.rb doc/*.rdoc doc/release_notes/*.txt"
|
62
|
+
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG COPYING lib/*.rb lib/sequel/*.rb lib/sequel/{connection_pool,dataset,database,model}/*.rb doc/*.rdoc doc/release_notes/*.txt"
|
63
63
|
end
|
64
64
|
|
65
65
|
Rake::RDocTask.new(:website_rdoc_adapters) do |rdoc|
|
@@ -114,10 +114,13 @@ a swiss army chainsaw.
|
|
114
114
|
|
115
115
|
=== Association callbacks
|
116
116
|
|
117
|
-
Sequel supports the same callbacks that ActiveRecord does
|
118
|
-
:before_remove, :after_add, and
|
119
|
-
|
120
|
-
|
117
|
+
Sequel supports the same callbacks that ActiveRecord does on one_to_many and
|
118
|
+
many_to_many associations: :before_add, :before_remove, :after_add, and
|
119
|
+
:after_remove. One many_to_one associations and one_to_one associations
|
120
|
+
(which are one_to_many associations with the :one_to_one option), Sequel
|
121
|
+
supports the :before_set and :after_set callbacks. On all associations,
|
122
|
+
Sequel supports :after_load, which is called after the association has been
|
123
|
+
loaded.
|
121
124
|
|
122
125
|
Each of these options can be a Symbol specifying an instance method
|
123
126
|
that takes one argument (the associated object), or a Proc that takes
|
@@ -129,12 +132,6 @@ If any of the before callbacks return false, the adding/removing
|
|
129
132
|
does not happen and it either raises an error (the default), or
|
130
133
|
returns nil (if raise_on_save_failure is false).
|
131
134
|
|
132
|
-
All callbacks are also run on many_to_one associations. If there
|
133
|
-
was already an existing object for the association, it calls the
|
134
|
-
remove callbacks on the existing object and the add callbacks on the
|
135
|
-
new object. The remove callback calls are placed around the add
|
136
|
-
callback calls.
|
137
|
-
|
138
135
|
=== Association extensions
|
139
136
|
|
140
137
|
All associations come with an association_dataset method that can be further filtered or
|
@@ -0,0 +1,286 @@
|
|
1
|
+
New Features
|
2
|
+
------------
|
3
|
+
|
4
|
+
* A real one_to_one association was added to Sequel, replacing the
|
5
|
+
previous :one_to_one option of the one_to_many association.
|
6
|
+
|
7
|
+
This is a fully backwards incompatible change, any code that uses
|
8
|
+
the :one_to_one option of one_to_many will be broken in Sequel
|
9
|
+
3.10.0, as that option now raises an exception. Keeping backwards
|
10
|
+
compatibility was not possible, as even the name of the association
|
11
|
+
needs to be changed. Here are the code changes you need to make:
|
12
|
+
|
13
|
+
* The association definition needs to change from one_to_many to
|
14
|
+
one_to_one, with no :one_to_one option, and with the association
|
15
|
+
name changed from the plural form to the singular form:
|
16
|
+
|
17
|
+
# Before
|
18
|
+
Lyric.one_to_many :songs, :one_to_one=>true
|
19
|
+
# After
|
20
|
+
Lyric.one_to_one :song
|
21
|
+
|
22
|
+
* All usage of the association when eager loading or when getting
|
23
|
+
reflections need to use the new singular association name:
|
24
|
+
|
25
|
+
# Before
|
26
|
+
Lyric.eager(:songs).all
|
27
|
+
Lyric.eager_graph(:songs).all
|
28
|
+
Lyric.association_reflection(:songs)
|
29
|
+
# After
|
30
|
+
Lyric.eager(:song).all
|
31
|
+
Lyric.eager_graph(:song).all
|
32
|
+
Lyric.association_reflection(:song)
|
33
|
+
|
34
|
+
Any Sequel plugins or extensions that deal with the internals of
|
35
|
+
associations need to be made aware of the one_to_one association,
|
36
|
+
and how it is different than one_to_many's previous :one_to_one
|
37
|
+
option. Here are some internal changes that may affect you:
|
38
|
+
|
39
|
+
* one_to_one associations are now cached like many_to_one
|
40
|
+
associations instead of like one_to_many associations. So the
|
41
|
+
cache includes the associated object or nil, instead of an array.
|
42
|
+
Note that this change means that all custom :eager_loader options
|
43
|
+
for one_to_one associations need to change to use this new
|
44
|
+
caching scheme.
|
45
|
+
|
46
|
+
* The one_to_one association setter method is now handled similarly
|
47
|
+
to the many_to_one setter method, instead of using the internal
|
48
|
+
one_to_many association add method.
|
49
|
+
|
50
|
+
* Instead of raising an error when multiple rows are returned,
|
51
|
+
one_to_one associations now use limit(1) to only return a single
|
52
|
+
row.
|
53
|
+
|
54
|
+
There were some other fixes made during these changes:
|
55
|
+
|
56
|
+
* The one_to_one setter now accepts nil to disassociate the record.
|
57
|
+
Previously, this raised an error.
|
58
|
+
|
59
|
+
* If the one_to_one association already had a separate object
|
60
|
+
associated, and you assigned a different object in the setter
|
61
|
+
method, Sequel now disassociates the old object before
|
62
|
+
associating the new object, fixing some potential issues if there
|
63
|
+
is a UNIQUE constraint on the foreign key column.
|
64
|
+
|
65
|
+
* Using the many_to_one association setter where the reciprocal
|
66
|
+
association is a one_to_one association with a currently
|
67
|
+
different cached associated object no longer raises an exception.
|
68
|
+
|
69
|
+
* The nested_attributes and association_dependencies plugins
|
70
|
+
both now correctly handle one_to_one associations.
|
71
|
+
|
72
|
+
If you need any help migrating, please post on the Sequel Google
|
73
|
+
Group or ask in the #sequel IRC channel.
|
74
|
+
|
75
|
+
* Both many_to_one and one_to_one associations now use before_set
|
76
|
+
and after_set callbacks instead of trying to make the one_to_many
|
77
|
+
and many_to_many associations' (before|after)_(add|remove)
|
78
|
+
callbacks work.
|
79
|
+
|
80
|
+
This change makes the code simpler, makes writing callbacks easier,
|
81
|
+
and no longer requires Sequel to send a query to the database to
|
82
|
+
get the currently associated object in the many_to_one association
|
83
|
+
setter method (you can still do so manually in a before_set
|
84
|
+
callback if you want to).
|
85
|
+
|
86
|
+
* Dataset#for_update was added as a default dataset method.
|
87
|
+
Previously, it was only supported on PostgreSQL. It has been
|
88
|
+
tested to work on PostgreSQL, MySQL, SQLite (where it is ignored),
|
89
|
+
H2, and MSSQL.
|
90
|
+
|
91
|
+
* Dataset#lock_style was added as a backbone for Dataset#for_update,
|
92
|
+
but allowing you to specify custom lock styles. These can either
|
93
|
+
be symbols recognized by the adapters, or strings which are treated
|
94
|
+
as literal SQL.
|
95
|
+
|
96
|
+
* Model#lock! was added, which uses Dataset#for_update to lock model
|
97
|
+
rows for specific instances. Combined with the Dataset#for_update,
|
98
|
+
Sequel now has an equivalent to ActiveRecord's pessimistic locking
|
99
|
+
support.
|
100
|
+
|
101
|
+
* A composition plugin was added, given similar functionality as
|
102
|
+
ActiveRecord's composed_of.
|
103
|
+
|
104
|
+
The composition plugin allows you to easily define getter and
|
105
|
+
setter instance methods for a class where the backing data is
|
106
|
+
composed of other getters and decomposed to other setters.
|
107
|
+
|
108
|
+
A simple example of this is when you have a database table with
|
109
|
+
separate columns for year, month, and day, but where you want to
|
110
|
+
deal with Date objects in your ruby code. This can be handled
|
111
|
+
with:
|
112
|
+
|
113
|
+
Model.composition :date, :mapping=>[:year, :month, :day]
|
114
|
+
|
115
|
+
The :mapping option is optional, but if not used, you need define
|
116
|
+
custom composition and decomposition procs via the :composer and
|
117
|
+
:decomposer options.
|
118
|
+
|
119
|
+
Note that when using the composition object, you should not modify
|
120
|
+
the underlying columns if you are also instantiating the
|
121
|
+
composition, as otherwise the composition object values will
|
122
|
+
override any underlying columns when the object is saved.
|
123
|
+
|
124
|
+
* An rcte_tree plugin was added, which uses recursive common table
|
125
|
+
expressions to load all ancestors and descendants in a single
|
126
|
+
query. If your database supports recursive common table
|
127
|
+
expressions (PostgreSQL 8.4+, MSSQL 2005+, newer versions of
|
128
|
+
Firebird), using recursive common table expressions to load
|
129
|
+
all ancestors and descendants is significantly faster than storing
|
130
|
+
trees as nested sets and using nested set queries. Usage:
|
131
|
+
|
132
|
+
Model.plugin :rcte_tree
|
133
|
+
|
134
|
+
# Lazy loading
|
135
|
+
model = Model.first
|
136
|
+
model.parent
|
137
|
+
model.children
|
138
|
+
model.ancestors # Populates :parent association as well
|
139
|
+
model.descendants # Populates :children association as well
|
140
|
+
|
141
|
+
# Eager loading - also populates the :parent and children
|
142
|
+
# associations for all ancestors and descendants
|
143
|
+
Model.filter(:id=>[1, 2]).eager(:ancestors, :descendants).all
|
144
|
+
|
145
|
+
# Eager loading children and grandchildren
|
146
|
+
Model.filter(:id=>[1, 2]).eager(:descendants=>2).all
|
147
|
+
# Eager loading children, grandchildren, and great grandchildren
|
148
|
+
Model.filter(:id=>[1, 2]).eager(:descendants=>3).all
|
149
|
+
|
150
|
+
* Dataset#first_source_table was added, giving you the unaliased
|
151
|
+
version of the table for the first source.
|
152
|
+
|
153
|
+
* Add Sequel::BasicObject.remove_methods!, useful on ruby 1.8 if you
|
154
|
+
require other libraries after Sequel that add methods to Object.
|
155
|
+
For example, if YAML is required after sequel, then the following
|
156
|
+
will raise an error:
|
157
|
+
|
158
|
+
DB[:a].filter{x > y}
|
159
|
+
|
160
|
+
because YAML adds the y method to all objects. Now, you can call
|
161
|
+
Sequel::BasicObject.remove_methods!, which will remove those
|
162
|
+
methods from Sequel::BasicObject, allowing them to be used as
|
163
|
+
intended in the above DSL.
|
164
|
+
|
165
|
+
* Sequel associations now accept an :eager_loader_key option, which
|
166
|
+
can be useful for associations to specify the column to use for the
|
167
|
+
key_hash for custom :eager_loaders.
|
168
|
+
|
169
|
+
* A JDBC subadapter for the AS400 database was added.
|
170
|
+
|
171
|
+
Other Improvements
|
172
|
+
------------------
|
173
|
+
|
174
|
+
* The one_to_one setter method and the one_to_many and many_to_many
|
175
|
+
remove_all methods now apply the association options (such as
|
176
|
+
filters) on the appropriate dataset:
|
177
|
+
|
178
|
+
Artist.one_to_many :good_albums, :class=>:Album,
|
179
|
+
:conditions=>{:good=>true}
|
180
|
+
a = Artist[10]
|
181
|
+
a.remove_all_good_albums
|
182
|
+
# Before: WHERE artist_id = 10
|
183
|
+
# After: WHERE artist_id = 10 AND good IS TRUE
|
184
|
+
|
185
|
+
* Plugin loading now works correctly when the plugin module name
|
186
|
+
is the same name as an already defined top level constant. This
|
187
|
+
means that the active_model plugin should now work correctly if
|
188
|
+
you require active_model before loading the Sequel plugin.
|
189
|
+
|
190
|
+
* The nested_attributes plugin now preserves nested attributes for
|
191
|
+
*_to_one associations on validation failures.
|
192
|
+
|
193
|
+
* Transactions now work correctly on Oracle when using the JDBC
|
194
|
+
adapter.
|
195
|
+
|
196
|
+
* Dataset#limit once again works correctly on MSSQL 2000. It was
|
197
|
+
broken in Sequel 3.9.0.
|
198
|
+
|
199
|
+
* many_to_one associations now use limit(1) to ensure only one
|
200
|
+
record is returned. If you don't want this (because maybe you
|
201
|
+
are using the :eager_graph association option), you need to
|
202
|
+
set the :key option to nil and use a custom :dataset option.
|
203
|
+
|
204
|
+
* many_to_one and one_to_many associations now work correctly
|
205
|
+
with the association :eager option to eagerly load associations
|
206
|
+
specified by :eager when lazy loading the association.
|
207
|
+
|
208
|
+
* The typecast_on_load plugin now correctly handles
|
209
|
+
reloading/refreshing the object, both explicitly and implicitly
|
210
|
+
on object creation.
|
211
|
+
|
212
|
+
* The schema parser and dumper now return tinyint columns as
|
213
|
+
booleans when connecting to mysql using the do adapter, since
|
214
|
+
DataObjects now returns the columns as booleans.
|
215
|
+
|
216
|
+
* The schema dumper now deals better with unusual or database
|
217
|
+
specific primary key types when using the :same_db option.
|
218
|
+
|
219
|
+
* On ruby 1.8, Sequel::BasicObject now undefs private methods in
|
220
|
+
addition to public and protected methods. So the following
|
221
|
+
code now works as expected:
|
222
|
+
|
223
|
+
DB[:a].filter{x > p} # WHERE x > p
|
224
|
+
|
225
|
+
* Sequel.connect with a block now returns the value of the block:
|
226
|
+
|
227
|
+
max_price = Sequel.connect('sqlite://items.db') do |db|
|
228
|
+
db[:items].max(:price)
|
229
|
+
end
|
230
|
+
|
231
|
+
* MSSQL emulated offset support now works correctly when Sequel's
|
232
|
+
core extensions are not loaded.
|
233
|
+
|
234
|
+
* Sequel::BasicObject now works correctly on rubinius, and almost
|
235
|
+
all Sequel specs now pass on rubinius.
|
236
|
+
|
237
|
+
* The nested_attributes plugin now uses a better exception message
|
238
|
+
no matching associated object is found.
|
239
|
+
|
240
|
+
* Sequel now raises a more informative error if you attempt to use
|
241
|
+
the native sqlite adapter with the sqlite3 gem instead of the
|
242
|
+
sqlite3-ruby gem.
|
243
|
+
|
244
|
+
* Multiple complex expressions with the same operator are now
|
245
|
+
combined for simpler SQL:
|
246
|
+
|
247
|
+
DB[:a].filter(:a=>1, :b=>2).filter(:c=>3)
|
248
|
+
# Before: (((a = 1) AND (b = 2)) AND (c = 3))
|
249
|
+
# After: ((a = 1) AND (b = 2) AND (c = 3))
|
250
|
+
|
251
|
+
* The Sequel::Model dataset methods (class methods proxied to the
|
252
|
+
model's dataset) and the Sequel::Dataset mutation methods
|
253
|
+
(methods that have a ! counterpart to modify the object in place)
|
254
|
+
have both been updated to use new dataset methods added in recent
|
255
|
+
versions.
|
256
|
+
|
257
|
+
Backwards Compatibility
|
258
|
+
-----------------------
|
259
|
+
|
260
|
+
* The :one_to_one option of the one_to_many associations now raises
|
261
|
+
an exception. Please see the section above about the new real
|
262
|
+
one_to_one association.
|
263
|
+
|
264
|
+
* The change to apply the association options to the one_to_many and
|
265
|
+
many_to_many remove_all methods has the potential to break some
|
266
|
+
code that uses the remove_all method on associations that use
|
267
|
+
association options. This is especially true for many_to_many
|
268
|
+
associations, as filters in many_to_many associations will often
|
269
|
+
reference columns in the associated table, while the dataset
|
270
|
+
used in the remove_all method only contains the join table. Such
|
271
|
+
cases should be handled by manually overriding the _remove_all
|
272
|
+
association instance method in the class. It was determined that
|
273
|
+
it was better to issue possibly invalid queries than to issue
|
274
|
+
queries that make unexpected modifications.
|
275
|
+
|
276
|
+
* Dataset#group_and_count now longer orders the dataset by the count.
|
277
|
+
Since it returns a modified dataset, if you want to order the
|
278
|
+
dataset, just call order on the returned dataset.
|
279
|
+
|
280
|
+
* many_to_one associations now require a working :class option.
|
281
|
+
Previously, if you provided a custom :dataset option, a working
|
282
|
+
:class option was not required in some cases.
|
283
|
+
|
284
|
+
* The MSSQL shared adapter dataset methods switched from using
|
285
|
+
the :table_options internal option key to using the :lock internal
|
286
|
+
option key.
|
@@ -22,6 +22,10 @@ module Sequel
|
|
22
22
|
def database_name
|
23
23
|
(m = /\/(.*)/.match(URI.parse(uri).path)) && m[1]
|
24
24
|
end
|
25
|
+
|
26
|
+
def schema_column_type(db_type)
|
27
|
+
db_type == 'tinyint(1)' ? :boolean : super
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
# Dataset class for MySQL datasets accessed via DataObjects.
|
data/lib/sequel/adapters/jdbc.rb
CHANGED
@@ -67,6 +67,11 @@ module Sequel
|
|
67
67
|
db.extend(Sequel::JDBC::H2::DatabaseMethods)
|
68
68
|
JDBC.load_gem('h2')
|
69
69
|
org.h2.Driver
|
70
|
+
end,
|
71
|
+
:as400=>proc do |db|
|
72
|
+
Sequel.ts_require 'adapters/jdbc/as400'
|
73
|
+
db.extend(Sequel::JDBC::AS400::DatabaseMethods)
|
74
|
+
com.ibm.as400.access.AS400JDBCDriver
|
70
75
|
end
|
71
76
|
}
|
72
77
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Sequel
|
2
|
+
module JDBC
|
3
|
+
# Database and Dataset support for AS400 databases accessed via JDBC.
|
4
|
+
module AS400
|
5
|
+
# Instance methods for AS400 Database objects accessed via JDBC.
|
6
|
+
module DatabaseMethods
|
7
|
+
# AS400 uses the :as400 database type.
|
8
|
+
def database_type
|
9
|
+
:as400
|
10
|
+
end
|
11
|
+
|
12
|
+
# Return Sequel::JDBC::AS400::Dataset object with the given opts.
|
13
|
+
def dataset(opts=nil)
|
14
|
+
Sequel::JDBC::AS400::Dataset.new(self, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: Fix for AS400
|
18
|
+
def last_insert_id(conn, opts={})
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Dataset class for AS400 datasets accessed via JDBC.
|
24
|
+
class Dataset < JDBC::Dataset
|
25
|
+
WILDCARD = Sequel::LiteralString.new('*').freeze
|
26
|
+
|
27
|
+
# AS400 needs to use a couple of subselects for all limits and offsets.
|
28
|
+
def select_sql
|
29
|
+
return super unless l = @opts[:limit]
|
30
|
+
o = @opts[:offset] || 0
|
31
|
+
order = @opts[:order]
|
32
|
+
dsa1 = dataset_alias(1)
|
33
|
+
dsa2 = dataset_alias(2)
|
34
|
+
rn = row_number_column
|
35
|
+
irn = Sequel::SQL::Identifier.new(rn).qualify(dsa2)
|
36
|
+
subselect_sql(unlimited.
|
37
|
+
from_self(:alias=>dsa1).
|
38
|
+
select_more(Sequel::SQL::QualifiedIdentifier.new(dsa1, WILDCARD),
|
39
|
+
Sequel::SQL::WindowFunction.new(SQL::Function.new(:ROW_NUMBER), Sequel::SQL::Window.new(:order=>order)).as(rn)).
|
40
|
+
from_self(:alias=>dsa2).
|
41
|
+
select(Sequel::SQL::QualifiedIdentifier.new(dsa2, WILDCARD)).
|
42
|
+
where((irn > o) & (irn <= l + o)))
|
43
|
+
end
|
44
|
+
|
45
|
+
def supports_window_functions?
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# The alias to use for the row_number column when emulating LIMIT and OFFSET
|
52
|
+
def row_number_column
|
53
|
+
:x_sequel_row_number_x
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|