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
@@ -124,6 +124,15 @@ describe Sequel::Model, "#eager" do
|
|
124
124
|
MODEL_DB.sqls.length.should == 2
|
125
125
|
end
|
126
126
|
|
127
|
+
it "should eagerly load a single one_to_one association" do
|
128
|
+
EagerAlbum.one_to_one :track, :class=>'EagerTrack', :key=>:album_id
|
129
|
+
a = EagerAlbum.eager(:track).all
|
130
|
+
a.should == [EagerAlbum.load(:id => 1, :band_id => 2)]
|
131
|
+
MODEL_DB.sqls.should == ['SELECT * FROM albums', 'SELECT * FROM tracks WHERE (tracks.album_id IN (1))']
|
132
|
+
a.first.track.should == EagerTrack.load(:id => 3, :album_id=>1)
|
133
|
+
MODEL_DB.sqls.length.should == 2
|
134
|
+
end
|
135
|
+
|
127
136
|
it "should eagerly load a single one_to_many association" do
|
128
137
|
a = EagerAlbum.eager(:tracks).all
|
129
138
|
a.should be_a_kind_of(Array)
|
@@ -718,6 +727,18 @@ describe Sequel::Model, "#eager_graph" do
|
|
718
727
|
a.band.should be_a_kind_of(GraphBand)
|
719
728
|
a.band.values.should == {:id => 2, :vocalist_id=>3}
|
720
729
|
end
|
730
|
+
|
731
|
+
it "should eagerly load a single one_to_one association" do
|
732
|
+
GraphAlbum.one_to_one :track, :class=>'GraphTrack', :key=>:album_id
|
733
|
+
ds = GraphAlbum.eager_graph(:track)
|
734
|
+
ds.sql.should == 'SELECT albums.id, albums.band_id, track.id AS track_id, track.album_id FROM albums LEFT OUTER JOIN tracks AS track ON (track.album_id = albums.id)'
|
735
|
+
def ds.fetch_rows(sql, &block)
|
736
|
+
yield({:id=>1, :band_id=>2, :track_id=>3, :album_id=>1})
|
737
|
+
end
|
738
|
+
a = ds.all
|
739
|
+
a.should == [GraphAlbum.load(:id => 1, :band_id => 2)]
|
740
|
+
a.first.track.should == GraphTrack.load(:id => 3, :album_id=>1)
|
741
|
+
end
|
721
742
|
|
722
743
|
it "should eagerly load a single one_to_many association" do
|
723
744
|
ds = GraphAlbum.eager_graph(:tracks)
|
@@ -1211,7 +1232,7 @@ describe Sequel::Model, "#eager_graph" do
|
|
1211
1232
|
GraphAlbum.eager_graph(:active_band).sql.should == "SELECT albums.id, albums.band_id, active_band.id AS active_band_id, active_band.vocalist_id FROM albums LEFT OUTER JOIN bands AS active_band ON ((active_band.id = albums.band_id) AND (active_band.active IS TRUE))"
|
1212
1233
|
|
1213
1234
|
GraphAlbum.one_to_many :right_tracks, :class=>'GraphTrack', :key=>:album_id, :conditions=>{:id=>(0..100)}
|
1214
|
-
GraphAlbum.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, right_tracks.id AS right_tracks_id, right_tracks.album_id FROM albums LEFT OUTER JOIN tracks AS right_tracks ON ((right_tracks.album_id = albums.id) AND (
|
1235
|
+
GraphAlbum.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, right_tracks.id AS right_tracks_id, right_tracks.album_id FROM albums LEFT OUTER JOIN tracks AS right_tracks ON ((right_tracks.album_id = albums.id) AND (right_tracks.id >= 0) AND (right_tracks.id <= 100))'
|
1215
1236
|
|
1216
1237
|
GraphAlbum.many_to_many :active_genres, :class=>'GraphGenre', :left_key=>:album_id, :right_key=>:genre_id, :join_table=>:ag, :conditions=>{true=>:active}
|
1217
1238
|
GraphAlbum.eager_graph(:active_genres).sql.should == "SELECT albums.id, albums.band_id, active_genres.id AS active_genres_id FROM albums LEFT OUTER JOIN ag ON (ag.album_id = albums.id) LEFT OUTER JOIN genres AS active_genres ON ((active_genres.id = ag.genre_id) AND ('t' = ag.active))"
|
@@ -1222,7 +1243,7 @@ describe Sequel::Model, "#eager_graph" do
|
|
1222
1243
|
GraphAlbum.eager_graph(:active_band).sql.should == "SELECT albums.id, albums.band_id, active_band.id AS active_band_id, active_band.vocalist_id FROM albums LEFT OUTER JOIN bands AS active_band ON ((active_band.id = albums.band_id) AND (active_band.active IS TRUE))"
|
1223
1244
|
|
1224
1245
|
GraphAlbum.one_to_many :right_tracks, :class=>'GraphTrack', :key=>:album_id, :graph_conditions=>{:id=>(0..100)}
|
1225
|
-
GraphAlbum.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, right_tracks.id AS right_tracks_id, right_tracks.album_id FROM albums LEFT OUTER JOIN tracks AS right_tracks ON ((right_tracks.album_id = albums.id) AND (
|
1246
|
+
GraphAlbum.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, right_tracks.id AS right_tracks_id, right_tracks.album_id FROM albums LEFT OUTER JOIN tracks AS right_tracks ON ((right_tracks.album_id = albums.id) AND (right_tracks.id >= 0) AND (right_tracks.id <= 100))'
|
1226
1247
|
|
1227
1248
|
GraphAlbum.many_to_many :active_genres, :class=>'GraphGenre', :left_key=>:album_id, :right_key=>:genre_id, :join_table=>:ag, :graph_conditions=>{true=>:active}
|
1228
1249
|
GraphAlbum.eager_graph(:active_genres).sql.should == "SELECT albums.id, albums.band_id, active_genres.id AS active_genres_id FROM albums LEFT OUTER JOIN ag ON (ag.album_id = albums.id) LEFT OUTER JOIN genres AS active_genres ON ((active_genres.id = ag.genre_id) AND ('t' = ag.active))"
|
@@ -1241,7 +1262,7 @@ describe Sequel::Model, "#eager_graph" do
|
|
1241
1262
|
GraphAlbum.eager_graph(:active_band).sql.should == "SELECT albums.id, albums.band_id, active_band.id AS active_band_id, active_band.vocalist_id FROM albums LEFT OUTER JOIN bands AS active_band ON ((active_band.id = albums.band_id) AND (active_band.active IS TRUE))"
|
1242
1263
|
|
1243
1264
|
GraphAlbum.one_to_many :right_tracks, :class=>'GraphTrack', :key=>:album_id, :graph_block=>proc{|ja,lja,js| {:id.qualify(ja)=>(0..100)}}
|
1244
|
-
GraphAlbum.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, right_tracks.id AS right_tracks_id, right_tracks.album_id FROM albums LEFT OUTER JOIN tracks AS right_tracks ON ((right_tracks.album_id = albums.id) AND (
|
1265
|
+
GraphAlbum.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, right_tracks.id AS right_tracks_id, right_tracks.album_id FROM albums LEFT OUTER JOIN tracks AS right_tracks ON ((right_tracks.album_id = albums.id) AND (right_tracks.id >= 0) AND (right_tracks.id <= 100))'
|
1245
1266
|
|
1246
1267
|
GraphAlbum.many_to_many :active_genres, :class=>'GraphGenre', :left_key=>:album_id, :right_key=>:genre_id, :join_table=>:ag, :graph_block=>proc{|ja,lja,js| {true=>:active.qualify(lja)}}
|
1247
1268
|
GraphAlbum.eager_graph(:active_genres).sql.should == "SELECT albums.id, albums.band_id, active_genres.id AS active_genres_id FROM albums LEFT OUTER JOIN ag ON (ag.album_id = albums.id) LEFT OUTER JOIN genres AS active_genres ON ((active_genres.id = ag.genre_id) AND ('t' = ag.active))"
|
data/spec/model/record_spec.rb
CHANGED
@@ -1433,3 +1433,37 @@ describe Sequel::Model, "typecasting" do
|
|
1433
1433
|
model.x.should == 'a'
|
1434
1434
|
end
|
1435
1435
|
end
|
1436
|
+
|
1437
|
+
describe "Model#lock!" do
|
1438
|
+
before do
|
1439
|
+
@c = Class.new(Sequel::Model(:items)) do
|
1440
|
+
columns :id
|
1441
|
+
end
|
1442
|
+
ds = @c.dataset
|
1443
|
+
def ds.fetch_rows(sql)
|
1444
|
+
db.execute(sql)
|
1445
|
+
yield({:id=>1})
|
1446
|
+
end
|
1447
|
+
MODEL_DB.reset
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
it "should do nothing if the record is a new record" do
|
1451
|
+
o = @c.new
|
1452
|
+
called = false
|
1453
|
+
o.meta_def(:_refresh){|x| called = true; super(x)}
|
1454
|
+
x = o.lock!
|
1455
|
+
x.should == o
|
1456
|
+
called.should == false
|
1457
|
+
MODEL_DB.sqls.should == []
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
it "should refresh the record using for_update if it is not a new record" do
|
1461
|
+
o = @c.load(:id => 1)
|
1462
|
+
called = false
|
1463
|
+
o.meta_def(:_refresh){|x| called = true; super(x)}
|
1464
|
+
x = o.lock!
|
1465
|
+
x.should == o
|
1466
|
+
called.should == true
|
1467
|
+
MODEL_DB.sqls.should == ["SELECT * FROM items WHERE (id = 1) LIMIT 1 FOR UPDATE"]
|
1468
|
+
end
|
1469
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -60,6 +60,7 @@ extra_rdoc_files:
|
|
60
60
|
- doc/release_notes/3.7.0.txt
|
61
61
|
- doc/release_notes/3.8.0.txt
|
62
62
|
- doc/release_notes/3.9.0.txt
|
63
|
+
- doc/release_notes/3.10.0.txt
|
63
64
|
files:
|
64
65
|
- COPYING
|
65
66
|
- CHANGELOG
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- doc/release_notes/3.7.0.txt
|
101
102
|
- doc/release_notes/3.8.0.txt
|
102
103
|
- doc/release_notes/3.9.0.txt
|
104
|
+
- doc/release_notes/3.10.0.txt
|
103
105
|
- doc/schema.rdoc
|
104
106
|
- doc/sharding.rdoc
|
105
107
|
- doc/virtual_rows.rdoc
|
@@ -158,6 +160,8 @@ files:
|
|
158
160
|
- spec/extensions/typecast_on_load_spec.rb
|
159
161
|
- spec/extensions/validation_class_methods_spec.rb
|
160
162
|
- spec/extensions/validation_helpers_spec.rb
|
163
|
+
- spec/extensions/composition_spec.rb
|
164
|
+
- spec/extensions/rcte_tree_spec.rb
|
161
165
|
- spec/integration/associations_test.rb
|
162
166
|
- spec/integration/database_test.rb
|
163
167
|
- spec/integration/dataset_test.rb
|
@@ -204,6 +208,7 @@ files:
|
|
204
208
|
- lib/sequel/adapters/jdbc/oracle.rb
|
205
209
|
- lib/sequel/adapters/jdbc/postgresql.rb
|
206
210
|
- lib/sequel/adapters/jdbc/sqlite.rb
|
211
|
+
- lib/sequel/adapters/jdbc/as400.rb
|
207
212
|
- lib/sequel/adapters/mysql.rb
|
208
213
|
- lib/sequel/adapters/odbc.rb
|
209
214
|
- lib/sequel/adapters/odbc/mssql.rb
|
@@ -283,6 +288,8 @@ files:
|
|
283
288
|
- lib/sequel/plugins/typecast_on_load.rb
|
284
289
|
- lib/sequel/plugins/validation_class_methods.rb
|
285
290
|
- lib/sequel/plugins/validation_helpers.rb
|
291
|
+
- lib/sequel/plugins/composition.rb
|
292
|
+
- lib/sequel/plugins/rcte_tree.rb
|
286
293
|
- lib/sequel/sql.rb
|
287
294
|
- lib/sequel/timezones.rb
|
288
295
|
- lib/sequel/version.rb
|