sequel 4.39.0 → 4.40.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +34 -0
- data/README.rdoc +8 -4
- data/doc/active_record.rdoc +1 -1
- data/doc/advanced_associations.rdoc +7 -7
- data/doc/association_basics.rdoc +7 -7
- data/doc/cheat_sheet.rdoc +5 -3
- data/doc/core_extensions.rdoc +3 -3
- data/doc/dataset_filtering.rdoc +1 -1
- data/doc/object_model.rdoc +16 -7
- data/doc/postgresql.rdoc +3 -3
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.40.0.txt +179 -0
- data/doc/security.rdoc +2 -1
- data/doc/sql.rdoc +34 -18
- data/doc/testing.rdoc +1 -0
- data/doc/virtual_rows.rdoc +11 -2
- data/lib/sequel/adapters/jdbc/derby.rb +7 -1
- data/lib/sequel/adapters/jdbc/h2.rb +15 -1
- data/lib/sequel/adapters/oracle.rb +9 -5
- data/lib/sequel/adapters/postgres.rb +0 -1
- data/lib/sequel/adapters/shared/cubrid.rb +11 -11
- data/lib/sequel/adapters/shared/db2.rb +4 -8
- data/lib/sequel/adapters/shared/mssql.rb +41 -28
- data/lib/sequel/adapters/shared/mysql.rb +9 -6
- data/lib/sequel/adapters/shared/oracle.rb +16 -5
- data/lib/sequel/adapters/shared/postgres.rb +84 -45
- data/lib/sequel/adapters/shared/sqlanywhere.rb +29 -15
- data/lib/sequel/adapters/shared/sqlite.rb +6 -6
- data/lib/sequel/core.rb +61 -10
- data/lib/sequel/database/connecting.rb +2 -1
- data/lib/sequel/database/features.rb +7 -0
- data/lib/sequel/database/query.rb +1 -1
- data/lib/sequel/database/schema_methods.rb +30 -3
- data/lib/sequel/database/transactions.rb +4 -2
- data/lib/sequel/dataset/actions.rb +1 -1
- data/lib/sequel/dataset/graph.rb +6 -1
- data/lib/sequel/dataset/query.rb +14 -7
- data/lib/sequel/dataset/sql.rb +2 -2
- data/lib/sequel/extensions/core_extensions.rb +2 -1
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/s.rb +57 -0
- data/lib/sequel/extensions/set_overrides.rb +5 -1
- data/lib/sequel/extensions/sql_expr.rb +1 -0
- data/lib/sequel/extensions/symbol_aref.rb +71 -0
- data/lib/sequel/extensions/symbol_aref_refinement.rb +41 -0
- data/lib/sequel/extensions/symbol_as.rb +23 -0
- data/lib/sequel/extensions/symbol_as_refinement.rb +35 -0
- data/lib/sequel/model/base.rb +3 -3
- data/lib/sequel/plugins/class_table_inheritance.rb +14 -3
- data/lib/sequel/plugins/column_select.rb +4 -2
- data/lib/sequel/plugins/dataset_associations.rb +12 -4
- data/lib/sequel/plugins/insert_returning_select.rb +1 -1
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +1 -1
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/sql.rb +40 -8
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/firebird_spec.rb +3 -3
- data/spec/adapters/mssql_spec.rb +40 -40
- data/spec/adapters/mysql_spec.rb +5 -5
- data/spec/adapters/oracle_spec.rb +4 -4
- data/spec/adapters/postgres_spec.rb +135 -124
- data/spec/adapters/spec_helper.rb +1 -0
- data/spec/adapters/sqlite_spec.rb +6 -6
- data/spec/core/dataset_spec.rb +2 -2
- data/spec/core/expression_filters_spec.rb +43 -2
- data/spec/core/schema_spec.rb +35 -1
- data/spec/core_extensions_spec.rb +27 -0
- data/spec/extensions/class_table_inheritance_spec.rb +8 -0
- data/spec/extensions/column_select_spec.rb +8 -0
- data/spec/extensions/core_refinements_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +9 -0
- data/spec/extensions/insert_returning_select_spec.rb +20 -0
- data/spec/extensions/prepared_statements_spec.rb +7 -0
- data/spec/extensions/s_spec.rb +60 -0
- data/spec/extensions/symbol_aref_refinement_spec.rb +28 -0
- data/spec/extensions/symbol_as_refinement_spec.rb +21 -0
- data/spec/integration/associations_test.rb +62 -57
- data/spec/integration/dataset_test.rb +54 -54
- data/spec/integration/eager_loader_test.rb +7 -7
- data/spec/integration/plugin_test.rb +20 -20
- data/spec/integration/prepared_statement_test.rb +1 -1
- data/spec/integration/schema_test.rb +21 -0
- data/spec/integration/spec_helper.rb +1 -0
- metadata +12 -2
@@ -36,7 +36,7 @@ OneToOneEagerGraphLimitStrategies = shared_description do
|
|
36
36
|
@album.update(:artist => @artist)
|
37
37
|
diff_album = @diff_album.call
|
38
38
|
ar = @pr.call[1]
|
39
|
-
ds = Artist.order(:
|
39
|
+
ds = Artist.order(Sequel[:artists][:name])
|
40
40
|
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
41
41
|
|
42
42
|
a = ds.eager_graph_with_options(:first_album, limit_strategy).all
|
@@ -105,7 +105,7 @@ OneToManyEagerGraphLimitStrategies = shared_description do
|
|
105
105
|
middle_album = @middle_album.call
|
106
106
|
diff_album = @diff_album.call
|
107
107
|
ar = @pr.call[1]
|
108
|
-
ds = Artist.order(:
|
108
|
+
ds = Artist.order(Sequel[:artists][:name])
|
109
109
|
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
110
110
|
|
111
111
|
ars = ds.eager_graph_with_options(:first_two_albums, limit_strategy).all
|
@@ -164,7 +164,7 @@ OneThroughOneEagerGraphLimitStrategies = shared_description do
|
|
164
164
|
it "should correctly handle offsets when eager graphing one_through_one associations" do
|
165
165
|
tu, tv = @other_tags.call
|
166
166
|
al = @pr.call.first
|
167
|
-
ds = Album.order(:
|
167
|
+
ds = Album.order(Sequel[:albums][:name])
|
168
168
|
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
169
169
|
|
170
170
|
als = ds.eager_graph_with_options(:first_tag, limit_strategy).all
|
@@ -220,7 +220,7 @@ ManyToManyEagerGraphLimitStrategies = shared_description do
|
|
220
220
|
tu, tv = @other_tags.call
|
221
221
|
al = @pr.call.first
|
222
222
|
al.add_tag(tu)
|
223
|
-
ds = Album.order(:
|
223
|
+
ds = Album.order(Sequel[:albums][:name])
|
224
224
|
limit_strategy = {:limit_strategy=>(@els||{})[:eager_limit_strategy]}
|
225
225
|
|
226
226
|
als = ds.eager_graph_with_options(:first_two_tags, limit_strategy).all
|
@@ -287,7 +287,7 @@ ManyThroughManyEagerGraphLimitStrategies = shared_description do
|
|
287
287
|
al, ar, _ = @pr.call
|
288
288
|
al.update(:artist=>ar)
|
289
289
|
al.add_tag(tu)
|
290
|
-
ds = Artist.order(:
|
290
|
+
ds = Artist.order(Sequel[:artists][:name])
|
291
291
|
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
292
292
|
|
293
293
|
ars = ds.eager_graph_with_options(:first_two_tags, limit_strategy).all
|
@@ -350,7 +350,7 @@ OneThroughManyEagerGraphLimitStrategies = shared_description do
|
|
350
350
|
al, ar, _ = @pr.call
|
351
351
|
al.update(:artist=>ar)
|
352
352
|
al.add_tag(tu)
|
353
|
-
ds = Artist.order(:
|
353
|
+
ds = Artist.order(Sequel[:artists][:name])
|
354
354
|
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
355
355
|
|
356
356
|
ars = ds.eager_graph_with_options(:first_tag, limit_strategy).all
|
@@ -1060,7 +1060,7 @@ FilterByAssociationsOneToOneLimitStrategies = shared_description do
|
|
1060
1060
|
ds.exclude(:last_album=>@album).all.must_equal [@artist, ar]
|
1061
1061
|
ds.exclude(:last_album=>diff_album).all.must_equal [ar]
|
1062
1062
|
|
1063
|
-
Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(:
|
1063
|
+
Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(Sequel[:albums][:name]=>diff_album.name) end
|
1064
1064
|
ar.add_album(diff_album)
|
1065
1065
|
ds.where(:first_album=>[@album, diff_album]).all.must_equal [ar]
|
1066
1066
|
ds.exclude(:first_album=>[@album, diff_album]).all.must_equal [@artist]
|
@@ -1086,7 +1086,7 @@ FilterByAssociationsSingularLimitStrategies = shared_description do
|
|
1086
1086
|
ds.where(ar.pk_hash).second_albums.all.must_equal []
|
1087
1087
|
ds.where(ar.pk_hash).last_albums.all.must_equal []
|
1088
1088
|
|
1089
|
-
Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(:
|
1089
|
+
Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(Sequel[:albums][:name]=>diff_album.name) end
|
1090
1090
|
ar.add_album(diff_album)
|
1091
1091
|
ds.where(@artist.pk_hash).first_albums.all.must_equal []
|
1092
1092
|
ds.where(ar.pk_hash).first_albums.all.must_equal [diff_album]
|
@@ -1122,8 +1122,8 @@ FilterByAssociationsSingularLimitStrategies = shared_description do
|
|
1122
1122
|
ds.exclude(:last_tag=>tu).all.must_equal [@album]
|
1123
1123
|
ds.exclude(:last_tag=>tv).all.must_equal [al]
|
1124
1124
|
|
1125
|
-
Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(:
|
1126
|
-
Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(:
|
1125
|
+
Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1126
|
+
Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1127
1127
|
|
1128
1128
|
ds.where(:first_tag=>[@tag, tu]).all.must_equal [@album, al]
|
1129
1129
|
ds.exclude(:first_tag=>[@tag, tu]).all.must_equal []
|
@@ -1149,8 +1149,8 @@ FilterByAssociationsSingularLimitStrategies = shared_description do
|
|
1149
1149
|
ds.where(al.pk_hash).second_tags.all.must_equal []
|
1150
1150
|
ds.where(al.pk_hash).last_tags.all.must_equal [tu]
|
1151
1151
|
|
1152
|
-
Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(:
|
1153
|
-
Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(:
|
1152
|
+
Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1153
|
+
Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1154
1154
|
|
1155
1155
|
ds.where(@album.pk_hash).first_tags.all.must_equal [tu]
|
1156
1156
|
ds.where(@album.pk_hash).second_tags.all.must_equal [tv]
|
@@ -1196,8 +1196,8 @@ FilterByAssociationsSingularLimitStrategies = shared_description do
|
|
1196
1196
|
ds.exclude(:last_tag=>tu).all.must_equal [@artist]
|
1197
1197
|
ds.exclude(:last_tag=>tv).all.must_equal [ar]
|
1198
1198
|
|
1199
|
-
Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(:
|
1200
|
-
Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(:
|
1199
|
+
Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1200
|
+
Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1201
1201
|
|
1202
1202
|
ds.where(:first_tag=>[@tag, tu]).all.must_equal [@artist, ar]
|
1203
1203
|
ds.exclude(:first_tag=>[@tag, tu]).all.must_equal []
|
@@ -1225,8 +1225,8 @@ FilterByAssociationsSingularLimitStrategies = shared_description do
|
|
1225
1225
|
ds.where(ar.pk_hash).second_tags.all.must_equal []
|
1226
1226
|
ds.where(ar.pk_hash).last_tags.all.must_equal [tu]
|
1227
1227
|
|
1228
|
-
Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(:
|
1229
|
-
Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(:
|
1228
|
+
Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1229
|
+
Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1230
1230
|
|
1231
1231
|
ds.where(@artist.pk_hash).first_tags.all.must_equal [tu]
|
1232
1232
|
ds.where(@artist.pk_hash).second_tags.all.must_equal [tv]
|
@@ -1275,7 +1275,7 @@ FilterByAssociationsOneToManyLimitStrategies = shared_description do
|
|
1275
1275
|
ds.exclude(a=>diff_album).all.must_equal [ar]
|
1276
1276
|
end
|
1277
1277
|
|
1278
|
-
Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(:
|
1278
|
+
Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(Sequel[:albums][:name]=>diff_album.name) end
|
1279
1279
|
ar.add_album(diff_album)
|
1280
1280
|
ds.where(:first_two_albums=>[@album, diff_album]).all.must_equal [ar]
|
1281
1281
|
ds.exclude(:first_two_albums=>[@album, diff_album]).all.must_equal [@artist]
|
@@ -1306,7 +1306,7 @@ FilterByAssociationsLimitStrategies = shared_description do
|
|
1306
1306
|
ds.where(ar.pk_hash).not_first_albums.all.must_equal []
|
1307
1307
|
ds.where(ar.pk_hash).last_two_albums.all.must_equal []
|
1308
1308
|
|
1309
|
-
Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(:
|
1309
|
+
Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(Sequel[:albums][:name]=>[diff_album.name, middle_album.name]) end
|
1310
1310
|
ar.add_album(diff_album)
|
1311
1311
|
ds.where(@artist.pk_hash).first_two_albums.all.must_equal [middle_album]
|
1312
1312
|
ds.where(ar.pk_hash).first_two_albums.all.must_equal [diff_album]
|
@@ -1350,8 +1350,8 @@ FilterByAssociationsLimitStrategies = shared_description do
|
|
1350
1350
|
ds.exclude(:last_two_tags=>tu).all.must_equal []
|
1351
1351
|
ds.exclude(:last_two_tags=>tv).all.must_equal [al]
|
1352
1352
|
|
1353
|
-
Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(:
|
1354
|
-
Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(:
|
1353
|
+
Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1354
|
+
Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1355
1355
|
|
1356
1356
|
ds.where(:first_two_tags=>[@tag, tu]).all.must_equal [@album, al]
|
1357
1357
|
ds.exclude(:first_two_tags=>[@tag, tu]).all.must_equal []
|
@@ -1380,8 +1380,8 @@ FilterByAssociationsLimitStrategies = shared_description do
|
|
1380
1380
|
ds.where(al.pk_hash).not_first_tags.all.must_equal []
|
1381
1381
|
ds.where(al.pk_hash).last_two_tags.all.must_equal [tu]
|
1382
1382
|
|
1383
|
-
Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(:
|
1384
|
-
Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(:
|
1383
|
+
Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1384
|
+
Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1385
1385
|
|
1386
1386
|
ds.where(@album.pk_hash).first_two_tags.all.must_equal [tu]
|
1387
1387
|
ds.where(@album.pk_hash).second_two_tags.all.must_equal [tv]
|
@@ -1435,8 +1435,8 @@ FilterByAssociationsLimitStrategies = shared_description do
|
|
1435
1435
|
ds.exclude(:last_two_tags=>tu).all.must_equal []
|
1436
1436
|
ds.exclude(:last_two_tags=>tv).all.must_equal [ar]
|
1437
1437
|
|
1438
|
-
Artist.many_through_many :first_two_tags, :clone=>:first_tag do |ads| ads.where(:
|
1439
|
-
Artist.many_through_many :second_two_tags, :clone=>:first_tag do |ads| ads.where(:
|
1438
|
+
Artist.many_through_many :first_two_tags, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1439
|
+
Artist.many_through_many :second_two_tags, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>[tv.name, tu.name]) end
|
1440
1440
|
|
1441
1441
|
ds.where(:first_two_tags=>[@tag, tu]).all.must_equal [@artist, ar]
|
1442
1442
|
ds.exclude(:first_two_tags=>[@tag, tu]).all.must_equal []
|
@@ -1467,8 +1467,8 @@ FilterByAssociationsLimitStrategies = shared_description do
|
|
1467
1467
|
ds.where(ar.pk_hash).not_first_tags.all.must_equal []
|
1468
1468
|
ds.where(ar.pk_hash).last_two_tags.all.must_equal [tu]
|
1469
1469
|
|
1470
|
-
Artist.many_through_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(:
|
1471
|
-
Artist.many_through_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(:
|
1470
|
+
Artist.many_through_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1471
|
+
Artist.many_through_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1472
1472
|
|
1473
1473
|
ds.where(@artist.pk_hash).first_two_tags.all.must_equal [tu]
|
1474
1474
|
ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tv]
|
@@ -1624,6 +1624,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
|
|
1624
1624
|
Album.alias_tags.all.must_equal [@tag]
|
1625
1625
|
Artist.albums.all.must_equal [@album]
|
1626
1626
|
unless @no_many_through_many
|
1627
|
+
Album.mthm_tags.all.must_equal [@tag]
|
1627
1628
|
Album.first_tags.all.must_equal [@tag]
|
1628
1629
|
Artist.tags.all.must_equal [@tag]
|
1629
1630
|
Artist.first_tags.all.must_equal [@tag]
|
@@ -1848,28 +1849,30 @@ describe "Sequel::Model Simple Associations" do
|
|
1848
1849
|
one_to_one :first_a_album, :clone=>:a_albums
|
1849
1850
|
plugin :many_through_many
|
1850
1851
|
many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]]
|
1851
|
-
many_through_many :first_two_tags, :clone=>:tags, :order
|
1852
|
-
many_through_many :second_two_tags, :clone=>:tags, :order
|
1853
|
-
many_through_many :not_first_tags, :clone=>:tags, :order
|
1854
|
-
many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:
|
1855
|
-
many_through_many :t_tags, :clone=>:tags, :conditions=>{:
|
1856
|
-
one_through_many :first_tag, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :order
|
1852
|
+
many_through_many :first_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>2, :graph_order=>:name
|
1853
|
+
many_through_many :second_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[2, 1], :graph_order=>:name
|
1854
|
+
many_through_many :not_first_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[nil, 1], :graph_order=>:name
|
1855
|
+
many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(Sequel[:tags][:name]), :limit=>2, :graph_order=>Sequel.desc(:name)
|
1856
|
+
many_through_many :t_tags, :clone=>:tags, :conditions=>{Sequel[:tags][:name]=>'T'}
|
1857
|
+
one_through_many :first_tag, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :order=>Sequel[:tags][:name], :graph_order=>:name, :class=>:Tag
|
1857
1858
|
one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
1858
|
-
one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(:
|
1859
|
-
one_through_many :t_tag, :clone=>:first_tag, :conditions=>{:
|
1859
|
+
one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(Sequel[:tags][:name]), :graph_order=>Sequel.desc(:name)
|
1860
|
+
one_through_many :t_tag, :clone=>:first_tag, :conditions=>{Sequel[:tags][:name]=>'T'}
|
1860
1861
|
end
|
1861
1862
|
class ::Album < Sequel::Model(@db)
|
1862
1863
|
plugin :dataset_associations
|
1863
1864
|
many_to_one :artist, :reciprocal=>nil
|
1864
1865
|
many_to_one :a_artist, :clone=>:artist, :conditions=>{:name=>'Ar'}, :key=>:artist_id
|
1865
1866
|
many_to_many :tags, :right_key=>:tag_id
|
1866
|
-
|
1867
|
+
plugin :many_through_many
|
1868
|
+
many_through_many :mthm_tags, [[:albums_tags, :album_id, :tag_id]], :class=>:Tag
|
1869
|
+
many_to_many :alias_tags, :clone=>:tags, :join_table=>Sequel[:albums_tags].as(:at)
|
1867
1870
|
many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
|
1868
1871
|
many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
1869
1872
|
many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
1870
1873
|
many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
1871
1874
|
many_to_many :t_tags, :clone=>:tags, :conditions=>{:name=>'T'}
|
1872
|
-
many_to_many :alias_t_tags, :clone=>:t_tags, :join_table
|
1875
|
+
many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>Sequel[:albums_tags].as(:at)
|
1873
1876
|
one_through_one :first_tag, :clone=>:tags, :order=>:name
|
1874
1877
|
one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
1875
1878
|
one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
|
@@ -1970,9 +1973,9 @@ describe "Sequel::Model Simple Associations" do
|
|
1970
1973
|
@album.update(:artist => @artist)
|
1971
1974
|
@album.add_tag(@tag)
|
1972
1975
|
|
1973
|
-
Artist.set_dataset(:
|
1974
|
-
Album.set_dataset(:
|
1975
|
-
Tag.set_dataset(:
|
1976
|
+
Artist.set_dataset(Sequel[:artists].as(:ar))
|
1977
|
+
Album.set_dataset(Sequel[:albums].as(:a))
|
1978
|
+
Tag.set_dataset(Sequel[:tags].as(:t))
|
1976
1979
|
Artist.one_to_many :balbums, :class=>Album, :key=>:artist_id, :reciprocal=>nil
|
1977
1980
|
Album.many_to_many :btags, :class=>Tag, :join_table=>:albums_tags, :right_key=>:tag_id
|
1978
1981
|
Album.many_to_one :bartist, :class=>Artist, :key=>:artist_id
|
@@ -2069,17 +2072,17 @@ describe "Sequel::Model Simple Associations" do
|
|
2069
2072
|
end
|
2070
2073
|
|
2071
2074
|
it "should handle dataset associations with :dataset_associations_join options" do
|
2072
|
-
Album.many_to_many :tags, :right_key=>:tag_id, :select=>[Sequel.expr(:tags).*, :
|
2073
|
-
Artist.many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :select=>[Sequel.expr(:tags).*, :
|
2075
|
+
Album.many_to_many :tags, :right_key=>:tag_id, :select=>[Sequel.expr(:tags).*, Sequel[:albums_tags][:tag_id].as(:atid)], :dataset_associations_join=>true
|
2076
|
+
Artist.many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :select=>[Sequel.expr(:tags).*, Sequel[:albums_tags][:tag_id].as(:atid), Sequel[:albums][:artist_id].as(:aid)], :dataset_associations_join=>true
|
2074
2077
|
|
2075
|
-
Album.tags.order(:
|
2076
|
-
Artist.tags.order(:
|
2078
|
+
Album.tags.order(Sequel[:tags][:name]).first.must_equal nil
|
2079
|
+
Artist.tags.order(Sequel[:tags][:name]).first.must_equal nil
|
2077
2080
|
|
2078
2081
|
@album.add_tag(@tag)
|
2079
2082
|
@artist.add_album(@album)
|
2080
2083
|
|
2081
|
-
Album.tags.order(:
|
2082
|
-
Artist.tags.order(:
|
2084
|
+
Album.tags.order(Sequel[:tags][:name]).first.must_equal Tag.load(:id=>@tag.id, :name=>"T", :atid=>@tag.id)
|
2085
|
+
Artist.tags.order(Sequel[:tags][:name]).first.must_equal Tag.load(:id=>@tag.id, :name=>"T", :atid=>@tag.id, :aid=>@artist.id)
|
2083
2086
|
end
|
2084
2087
|
end
|
2085
2088
|
|
@@ -2135,15 +2138,15 @@ describe "Sequel::Model Composite Key Associations" do
|
|
2135
2138
|
one_to_one :first_a_album, :clone=>:a_albums
|
2136
2139
|
plugin :many_through_many
|
2137
2140
|
many_through_many :tags, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]]
|
2138
|
-
many_through_many :first_two_tags, :clone=>:tags, :order
|
2139
|
-
many_through_many :second_two_tags, :clone=>:tags, :order
|
2140
|
-
many_through_many :not_first_tags, :clone=>:tags, :order
|
2141
|
-
many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:
|
2142
|
-
many_through_many :t_tags, :clone=>:tags do |ds| ds.where(:
|
2143
|
-
one_through_many :first_tag, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :order
|
2141
|
+
many_through_many :first_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>2, :graph_order=>:name
|
2142
|
+
many_through_many :second_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[2, 1], :graph_order=>:name
|
2143
|
+
many_through_many :not_first_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[nil, 1], :graph_order=>:name
|
2144
|
+
many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(Sequel[:tags][:name]), :limit=>2, :graph_order=>Sequel.desc(:name)
|
2145
|
+
many_through_many :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2146
|
+
one_through_many :first_tag, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :order=>Sequel[:tags][:name], :graph_order=>:name, :class=>:Tag
|
2144
2147
|
one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
2145
|
-
one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(:
|
2146
|
-
one_through_many :t_tag, :clone=>:first_tag do |ds| ds.where(:
|
2148
|
+
one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(Sequel[:tags][:name]), :graph_order=>Sequel.desc(:name)
|
2149
|
+
one_through_many :t_tag, :clone=>:first_tag do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2147
2150
|
end
|
2148
2151
|
class ::Album < Sequel::Model(@db)
|
2149
2152
|
plugin :dataset_associations
|
@@ -2152,13 +2155,15 @@ describe "Sequel::Model Composite Key Associations" do
|
|
2152
2155
|
many_to_one :artist, :key=>[:artist_id1, :artist_id2], :reciprocal=>nil
|
2153
2156
|
many_to_one(:a_artist, :clone=>:artist){|ds| ds.where(:name=>'Ar')}
|
2154
2157
|
many_to_many :tags, :left_key=>[:album_id1, :album_id2], :right_key=>[:tag_id1, :tag_id2]
|
2155
|
-
|
2158
|
+
plugin :many_through_many
|
2159
|
+
many_through_many :mthm_tags, [[:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
|
2160
|
+
many_to_many :alias_tags, :clone=>:tags, :join_table=>Sequel[:albums_tags].as(:at)
|
2156
2161
|
many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
|
2157
2162
|
many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
2158
2163
|
many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
2159
2164
|
many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
2160
2165
|
many_to_many :t_tags, :clone=>:tags do |ds| ds.where(:name=>'T') end
|
2161
|
-
many_to_many :alias_t_tags, :clone=>:t_tags, :join_table
|
2166
|
+
many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>Sequel[:albums_tags].as(:at)
|
2162
2167
|
one_through_one :first_tag, :clone=>:tags, :order=>:name
|
2163
2168
|
one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
2164
2169
|
one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
|
@@ -2283,7 +2288,7 @@ describe "Sequel::Model pg_array_to_many" do
|
|
2283
2288
|
pg_array_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
2284
2289
|
pg_array_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
2285
2290
|
pg_array_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
2286
|
-
pg_array_to_many :t_tags, :clone=>:tags do |ds| ds.where(:
|
2291
|
+
pg_array_to_many :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2287
2292
|
pg_array_to_many :alias_t_tags, :clone=>:t_tags
|
2288
2293
|
end
|
2289
2294
|
class ::Tag < Sequel::Model(@db)
|
@@ -2364,7 +2369,7 @@ describe "Sequel::Model many_to_pg_array" do
|
|
2364
2369
|
many_to_pg_array :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
2365
2370
|
many_to_pg_array :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
2366
2371
|
many_to_pg_array :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
2367
|
-
many_to_pg_array :t_tags, :clone=>:tags do |ds| ds.where(:
|
2372
|
+
many_to_pg_array :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2368
2373
|
many_to_pg_array :alias_t_tags, :clone=>:t_tags
|
2369
2374
|
end
|
2370
2375
|
class ::Tag < Sequel::Model(@db)
|
@@ -56,29 +56,29 @@ describe "Simple Dataset operations" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should join correctly" do
|
59
|
-
@ds.join(:
|
59
|
+
@ds.join(Sequel[:items].as(:b), :id=>:id).select_all(:items).all.must_equal [{:id=>1, :number=>10}]
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should handle LATERAL subqueries correctly" do
|
63
63
|
@ds << {:number=>20}
|
64
|
-
@ds.from(:
|
65
|
-
@ds.from(:
|
66
|
-
@ds.from(:
|
67
|
-
@ds.from(:
|
68
|
-
@ds.from(:
|
69
|
-
@ds.from(:
|
64
|
+
@ds.from(Sequel[:items].as(:i), @ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
65
|
+
@ds.from(Sequel[:items].as(:i)).cross_join(@ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
66
|
+
@ds.from(Sequel[:items].as(:i)).join(@ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral, 1=>1).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
67
|
+
@ds.from(Sequel[:items].as(:i)).join(@ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral, 1=>0).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal []
|
68
|
+
@ds.from(Sequel[:items].as(:i)).left_join(@ds.from(Sequel[:items].as(:i2)).where(Sequel[:i2][:number]=>Sequel[:i][:number]).lateral, 1=>1).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
69
|
+
@ds.from(Sequel[:items].as(:i)).left_join(@ds.from(Sequel[:items].as(:i2)).where(Sequel[:i2][:number]=>Sequel[:i][:number]).lateral, 1=>0).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, nil], [20, nil]]
|
70
70
|
end if DB.dataset.supports_lateral_subqueries?
|
71
71
|
|
72
72
|
it "should correctly deal with qualified columns and subselects" do
|
73
|
-
@ds.from_self(:alias=>:a).select(:
|
74
|
-
@ds.join(@ds.as(:a), :id=>:id).select(:
|
73
|
+
@ds.from_self(:alias=>:a).select(Sequel[:a][:id], Sequel.qualify(:a, :number)).all.must_equal [{:id=>1, :number=>10}]
|
74
|
+
@ds.join(@ds.as(:a), :id=>:id).select(Sequel[:a][:id], Sequel.qualify(:a, :number)).all.must_equal [{:id=>1, :number=>10}]
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should graph correctly" do
|
78
78
|
a = [{:items=>{:id=>1, :number=>10}, :b=>{:id=>1, :number=>10}}]
|
79
79
|
pr = proc{|t| @ds.graph(t, {:id=>:id}, :table_alias=>:b).extension(:graph_each).all.must_equal a}
|
80
80
|
pr[:items]
|
81
|
-
pr[:
|
81
|
+
pr[Sequel[:items].as(:foo)]
|
82
82
|
pr[Sequel.identifier(:items)]
|
83
83
|
pr[Sequel.identifier('items')]
|
84
84
|
pr[Sequel.as(:items, :foo)]
|
@@ -260,25 +260,25 @@ describe "Simple Dataset operations" do
|
|
260
260
|
@db.create_table!(:items2){primary_key :id2; Integer :number2}
|
261
261
|
@db[:items2].insert(:number2=>10)
|
262
262
|
@ds.from(:items, :items2).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
263
|
-
@ds.from(:
|
263
|
+
@ds.from(Sequel[:items].as(:i), Sequel[:items2].as(:i2)).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
264
264
|
@ds.cross_join(:items2).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
265
|
-
@ds.from(:
|
266
|
-
@ds.cross_join(:
|
265
|
+
@ds.from(Sequel[:items].as(:i)).cross_join(Sequel[:items2].as(:i2)).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
266
|
+
@ds.cross_join(Sequel[:items2].as(:i)).cross_join(@db[:items2].select(Sequel[:id2].as(:id3), Sequel[:number2].as(:number3))).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10, :id3=>1, :number3=>10}]
|
267
267
|
|
268
268
|
@ds.from(:items, :items2).order(:id).limit(2, 1).all.must_equal []
|
269
|
-
@ds.from(:
|
269
|
+
@ds.from(Sequel[:items].as(:i), Sequel[:items2].as(:i2)).order(:id).limit(2, 1).all.must_equal []
|
270
270
|
@ds.cross_join(:items2).order(:id).limit(2, 1).all.must_equal []
|
271
|
-
@ds.from(:
|
272
|
-
@ds.cross_join(:
|
271
|
+
@ds.from(Sequel[:items].as(:i)).cross_join(Sequel[:items2].as(:i2)).order(:id).limit(2, 1).all.must_equal []
|
272
|
+
@ds.cross_join(Sequel[:items2].as(:i)).cross_join(@db[:items2].select(Sequel[:id2].as(:id3), Sequel[:number2].as(:number3))).order(:id).limit(2, 1).all.must_equal []
|
273
273
|
@db.drop_table(:items2)
|
274
274
|
end
|
275
275
|
|
276
276
|
it "should fetch correctly with a limit and offset without an order" do
|
277
277
|
@ds.limit(2, 1).all.must_equal []
|
278
|
-
@ds.join(:
|
279
|
-
@ds.join(:
|
280
|
-
@ds.join(:
|
281
|
-
@ds.join(:
|
278
|
+
@ds.join(Sequel[:items].as(:i), :id=>:id).select(Sequel[:items][:id].as(:s), Sequel[:i][:id].as(:id2)).limit(2, 1).all.must_equal []
|
279
|
+
@ds.join(Sequel[:items].as(:i), :id=>:id).select(Sequel[:items][:id]).limit(2, 1).all.must_equal []
|
280
|
+
@ds.join(Sequel[:items].as(:i), :id=>:id).select(Sequel.qualify(:items, :id)).limit(2, 1).all.must_equal []
|
281
|
+
@ds.join(Sequel[:items].as(:i), :id=>:id).select(Sequel.qualify(:items, :id).as(:s)).limit(2, 1).all.must_equal []
|
282
282
|
end
|
283
283
|
|
284
284
|
it "should be orderable by column number" do
|
@@ -330,7 +330,7 @@ describe "Simple Dataset operations" do
|
|
330
330
|
end
|
331
331
|
|
332
332
|
it "should alias columns correctly" do
|
333
|
-
@ds.select(:
|
333
|
+
@ds.select(Sequel[:id].as(:x), Sequel[:number].as(:n)).first.must_equal(:x=>1, :n=>10)
|
334
334
|
end
|
335
335
|
|
336
336
|
it "should support table aliases with column aliases" do
|
@@ -700,17 +700,17 @@ if DB.dataset.supports_cte?
|
|
700
700
|
end
|
701
701
|
|
702
702
|
cspecify "should give correct results for recursive WITH", :db2 do
|
703
|
-
ds = @db[:t].select(:
|
703
|
+
ds = @db[:t].select(Sequel[:i].as(:id), Sequel[:pi].as(:parent_id)).with_recursive(:t, @ds.filter(:parent_id=>nil), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi]).order(:id)
|
704
704
|
ds.all.must_equal [{:parent_id=>nil, :id=>1}, {:parent_id=>nil, :id=>2}, {:parent_id=>1, :id=>3}, {:parent_id=>1, :id=>4}, {:parent_id=>3, :id=>5}, {:parent_id=>5, :id=>6}]
|
705
|
-
ps = @db[:t].select(:
|
705
|
+
ps = @db[:t].select(Sequel[:i].as(:id), Sequel[:pi].as(:parent_id)).with_recursive(:t, @ds.filter(:parent_id=>:$n), @ds.join(:t, :i=>:parent_id).filter(Sequel[:t][:i]=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi]).order(:id).prepare(:select, :cte_sel)
|
706
706
|
ps.call(:n=>1).must_equal [{:id=>3, :parent_id=>1}, {:id=>4, :parent_id=>1}, {:id=>5, :parent_id=>3}, {:id=>6, :parent_id=>5}]
|
707
707
|
ps.call(:n=>3).must_equal [{:id=>5, :parent_id=>3}, {:id=>6, :parent_id=>5}]
|
708
708
|
ps.call(:n=>5).must_equal [{:id=>6, :parent_id=>5}]
|
709
709
|
end
|
710
710
|
|
711
711
|
it "should support joining a dataset with a CTE" do
|
712
|
-
@ds.inner_join(@db[:t].with(:t, @ds.filter(:parent_id=>nil)), :id => :id).select(:
|
713
|
-
@db[:t].with(:t, @ds).inner_join(@db[:s].with(:s, @ds.filter(:parent_id=>nil)), :id => :id).select(:
|
712
|
+
@ds.inner_join(@db[:t].with(:t, @ds.filter(:parent_id=>nil)), :id => :id).select(Sequel[:i1][:id]).order(Sequel[:i1][:id]).map(:id).must_equal [1,2]
|
713
|
+
@db[:t].with(:t, @ds).inner_join(@db[:s].with(:s, @ds.filter(:parent_id=>nil)), :id => :id).select(Sequel[:t][:id]).order(Sequel[:t][:id]).map(:id).must_equal [1,2]
|
714
714
|
end
|
715
715
|
|
716
716
|
it "should support a subselect in the FROM clause with a CTE" do
|
@@ -777,7 +777,7 @@ if DB.dataset.supports_returning?(:insert)
|
|
777
777
|
h.must_equal(:id=>3)
|
778
778
|
@ds.returning.insert(5, 6){|r| h = r}
|
779
779
|
h.must_equal(:id=>5, :foo=>6)
|
780
|
-
@ds.returning(:
|
780
|
+
@ds.returning(Sequel[:id].as(:foo), Sequel[:foo].as(:id)).insert(7, 8){|r| h = r}
|
781
781
|
h.must_equal(:id=>8, :foo=>7)
|
782
782
|
end
|
783
783
|
end
|
@@ -806,7 +806,7 @@ if DB.dataset.supports_returning?(:update) # Assume DELETE support as well
|
|
806
806
|
@ds.returning.update(:id=>Sequel.+(:id, 1), :foo=>Sequel.*(:foo, 2)){|r| h << r}
|
807
807
|
h.must_equal [{:id=>4, :foo=>16}]
|
808
808
|
h.clear
|
809
|
-
@ds.returning(:
|
809
|
+
@ds.returning(Sequel[:id].as(:foo), Sequel[:foo].as(:id)).update(:id=>Sequel.+(:id, 1), :foo=>Sequel.*(:foo, 2)){|r| h << r}
|
810
810
|
h.must_equal [{:id=>32, :foo=>5}]
|
811
811
|
h.clear
|
812
812
|
|
@@ -1072,13 +1072,13 @@ describe "Sequel::Dataset convenience methods" do
|
|
1072
1072
|
end
|
1073
1073
|
|
1074
1074
|
it "#group_and_count should support column aliases" do
|
1075
|
-
@ds.group_and_count(:
|
1075
|
+
@ds.group_and_count(Sequel[:a].as(:c)).order{count(:a)}.all.must_equal []
|
1076
1076
|
@ds.insert(20, 10)
|
1077
|
-
@ds.group_and_count(:
|
1077
|
+
@ds.group_and_count(Sequel[:a].as(:c)).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:c=>20, :count=>1}]
|
1078
1078
|
@ds.insert(20, 30)
|
1079
|
-
@ds.group_and_count(:
|
1079
|
+
@ds.group_and_count(Sequel[:a].as(:c)).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:c=>20, :count=>2}]
|
1080
1080
|
@ds.insert(30, 30)
|
1081
|
-
@ds.group_and_count(:
|
1081
|
+
@ds.group_and_count(Sequel[:a].as(:c)).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:c=>30, :count=>1}, {:c=>20, :count=>2}]
|
1082
1082
|
end
|
1083
1083
|
|
1084
1084
|
it "#range should return the range between the maximum and minimum values" do
|
@@ -1112,10 +1112,10 @@ describe "Sequel::Dataset main SQL methods" do
|
|
1112
1112
|
end
|
1113
1113
|
|
1114
1114
|
it "#exists should return a usable exists clause" do
|
1115
|
-
@ds.filter(@db[:
|
1115
|
+
@ds.filter(@db[Sequel[:d].as(:c)].filter(Sequel[:c][:a]=>Sequel[:d][:b]).exists).all.must_equal []
|
1116
1116
|
@ds.insert(20, 30)
|
1117
1117
|
@ds.insert(10, 20)
|
1118
|
-
@ds.filter(@db[:
|
1118
|
+
@ds.filter(@db[Sequel[:d].as(:c)].filter(Sequel[:c][:a]=>Sequel[:d][:b]).exists).all.must_equal [{:a=>10, :b=>20}]
|
1119
1119
|
end
|
1120
1120
|
|
1121
1121
|
it "#filter and #exclude should work with placeholder strings" do
|
@@ -1147,7 +1147,7 @@ describe "Sequel::Dataset main SQL methods" do
|
|
1147
1147
|
it "#select_group should work correctly when aliasing" do
|
1148
1148
|
@ds.unordered!
|
1149
1149
|
@ds.insert(20, 30)
|
1150
|
-
@ds.select_group(:
|
1150
|
+
@ds.select_group(Sequel[:b].as(:c)).all.must_equal [{:c=>30}]
|
1151
1151
|
end
|
1152
1152
|
|
1153
1153
|
it "#having should work correctly" do
|
@@ -1224,36 +1224,36 @@ describe "Sequel::Dataset convenience methods" do
|
|
1224
1224
|
@ds.select_map([:a]).must_equal [[1], [5]]
|
1225
1225
|
@ds.select_map([:a, :b]).must_equal [[1, 2], [5, 6]]
|
1226
1226
|
|
1227
|
-
@ds.select_map(:
|
1228
|
-
@ds.select_map(:
|
1229
|
-
@ds.select_map([:
|
1230
|
-
@ds.select_map([:
|
1231
|
-
@ds.select_map([Sequel.expr(:
|
1227
|
+
@ds.select_map(Sequel[:a].as(:e)).must_equal [1, 5]
|
1228
|
+
@ds.select_map(Sequel[:b].as(:e)).must_equal [2, 6]
|
1229
|
+
@ds.select_map([Sequel[:a].as(:e), Sequel[:b].as(:f)]).must_equal [[1, 2], [5, 6]]
|
1230
|
+
@ds.select_map([Sequel[:a][:a].as(:e), Sequel[:a][:b].as(:f)]).must_equal [[1, 2], [5, 6]]
|
1231
|
+
@ds.select_map([Sequel.expr(Sequel[:a][:a]).as(:e), Sequel.expr(Sequel[:a][:b]).as(:f)]).must_equal [[1, 2], [5, 6]]
|
1232
1232
|
@ds.select_map([Sequel.qualify(:a, :a).as(:e), Sequel.qualify(:a, :b).as(:f)]).must_equal [[1, 2], [5, 6]]
|
1233
1233
|
@ds.select_map([Sequel.identifier(:a).qualify(:a).as(:e), Sequel.qualify(:a, :b).as(:f)]).must_equal [[1, 2], [5, 6]]
|
1234
1234
|
end
|
1235
1235
|
|
1236
1236
|
it "should have working #select_order_map" do
|
1237
1237
|
@ds.select_order_map(:a).must_equal [1, 5]
|
1238
|
-
@ds.select_order_map(Sequel.desc(:
|
1239
|
-
@ds.select_order_map(Sequel.desc(:
|
1238
|
+
@ds.select_order_map(Sequel.desc(Sequel[:a][:b])).must_equal [6, 2]
|
1239
|
+
@ds.select_order_map(Sequel.desc(Sequel[:a][:b].as(:e))).must_equal [6, 2]
|
1240
1240
|
@ds.select_order_map(Sequel.qualify(:a, :b).as(:e)).must_equal [2, 6]
|
1241
1241
|
@ds.select_order_map([:a]).must_equal [[1], [5]]
|
1242
1242
|
@ds.select_order_map([Sequel.desc(:a), :b]).must_equal [[5, 6], [1, 2]]
|
1243
1243
|
|
1244
|
-
@ds.select_order_map(:
|
1245
|
-
@ds.select_order_map(:
|
1246
|
-
@ds.select_order_map([Sequel.desc(:
|
1247
|
-
@ds.select_order_map([Sequel.desc(:
|
1248
|
-
@ds.select_order_map([Sequel.desc(:
|
1244
|
+
@ds.select_order_map(Sequel[:a].as(:e)).must_equal [1, 5]
|
1245
|
+
@ds.select_order_map(Sequel[:b].as(:e)).must_equal [2, 6]
|
1246
|
+
@ds.select_order_map([Sequel.desc(Sequel[:a].as(:e)), Sequel[:b].as(:f)]).must_equal [[5, 6], [1, 2]]
|
1247
|
+
@ds.select_order_map([Sequel.desc(Sequel[:a][:a].as(:e)), Sequel[:a][:b].as(:f)]).must_equal [[5, 6], [1, 2]]
|
1248
|
+
@ds.select_order_map([Sequel.desc(Sequel[:a][:a]), Sequel.expr(Sequel[:a][:b]).as(:f)]).must_equal [[5, 6], [1, 2]]
|
1249
1249
|
@ds.select_order_map([Sequel.qualify(:a, :a).desc, Sequel.qualify(:a, :b).as(:f)]).must_equal [[5, 6], [1, 2]]
|
1250
1250
|
@ds.select_order_map([Sequel.identifier(:a).qualify(:a).desc, Sequel.qualify(:a, :b).as(:f)]).must_equal [[5, 6], [1, 2]]
|
1251
1251
|
end
|
1252
1252
|
|
1253
1253
|
it "should have working #select_hash" do
|
1254
1254
|
@ds.select_hash(:a, :b).must_equal(1=>2, 5=>6)
|
1255
|
-
@ds.select_hash(:
|
1256
|
-
@ds.select_hash(Sequel.expr(:
|
1255
|
+
@ds.select_hash(Sequel[:a][:a].as(:e), :b).must_equal(1=>2, 5=>6)
|
1256
|
+
@ds.select_hash(Sequel.expr(Sequel[:a][:a]).as(:e), :b).must_equal(1=>2, 5=>6)
|
1257
1257
|
@ds.select_hash(Sequel.qualify(:a, :a).as(:e), :b).must_equal(1=>2, 5=>6)
|
1258
1258
|
@ds.select_hash(Sequel.identifier(:a).qualify(:a).as(:e), :b).must_equal(1=>2, 5=>6)
|
1259
1259
|
@ds.select_hash([:a, :c], :b).must_equal([1, 3]=>2, [5, 7]=>6)
|
@@ -1266,8 +1266,8 @@ describe "Sequel::Dataset convenience methods" do
|
|
1266
1266
|
ds = @ds.order(*@ds.columns)
|
1267
1267
|
ds.insert(1, 2, 3, 9)
|
1268
1268
|
ds.select_hash_groups(:a, :d).must_equal(1=>[4, 9], 5=>[8])
|
1269
|
-
ds.select_hash_groups(:
|
1270
|
-
ds.select_hash_groups(Sequel.expr(:
|
1269
|
+
ds.select_hash_groups(Sequel[:a][:a].as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1270
|
+
ds.select_hash_groups(Sequel.expr(Sequel[:a][:a]).as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1271
1271
|
ds.select_hash_groups(Sequel.qualify(:a, :a).as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1272
1272
|
ds.select_hash_groups(Sequel.identifier(:a).qualify(:a).as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1273
1273
|
ds.select_hash_groups([:a, :c], :d).must_equal([1, 3]=>[4, 9], [5, 7]=>[8])
|
@@ -1371,15 +1371,15 @@ describe "Sequel::Dataset DSL support" do
|
|
1371
1371
|
|
1372
1372
|
it "should work with qualifying" do
|
1373
1373
|
@ds.insert(10, 20)
|
1374
|
-
@ds.get(:
|
1375
|
-
@ds.get{
|
1374
|
+
@ds.get(Sequel[:a][:b]).must_equal 20
|
1375
|
+
@ds.get{a[:b]}.must_equal 20
|
1376
1376
|
@ds.get(Sequel.qualify(:a, :b)).must_equal 20
|
1377
1377
|
end
|
1378
1378
|
|
1379
1379
|
it "should work with aliasing" do
|
1380
1380
|
@ds.insert(10, 20)
|
1381
|
-
@ds.get(:
|
1382
|
-
@ds.get{
|
1381
|
+
@ds.get(Sequel[:a][:b].as(:c)).must_equal 20
|
1382
|
+
@ds.get{a[:b].as(c)}.must_equal 20
|
1383
1383
|
@ds.get(Sequel.qualify(:a, :b).as(:c)).must_equal 20
|
1384
1384
|
@ds.get(Sequel.as(:b, :c)).must_equal 20
|
1385
1385
|
end
|