sequel 4.39.0 → 4.40.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.
- 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
data/spec/adapters/mysql_spec.rb
CHANGED
@@ -177,14 +177,14 @@ describe "A MySQL dataset" do
|
|
177
177
|
@d.select(Sequel.lit('COUNT(*)')).sql.must_equal 'SELECT COUNT(*) FROM `items`'
|
178
178
|
@d.select(Sequel.function(:max, :value)).sql.must_equal 'SELECT max(`value`) FROM `items`'
|
179
179
|
@d.select(Sequel.function(:NOW)).sql.must_equal 'SELECT NOW() FROM `items`'
|
180
|
-
@d.select(Sequel.function(:max, :
|
180
|
+
@d.select(Sequel.function(:max, Sequel[:items][:value])).sql.must_equal 'SELECT max(`items`.`value`) FROM `items`'
|
181
181
|
@d.order(Sequel.expr(:name).desc).sql.must_equal 'SELECT * FROM `items` ORDER BY `name` DESC'
|
182
182
|
@d.select(Sequel.lit('items.name AS item_name')).sql.must_equal 'SELECT items.name AS item_name FROM `items`'
|
183
183
|
@d.select(Sequel.lit('`name`')).sql.must_equal 'SELECT `name` FROM `items`'
|
184
184
|
@d.select(Sequel.lit('max(items.`name`) AS `max_name`')).sql.must_equal 'SELECT max(items.`name`) AS `max_name` FROM `items`'
|
185
185
|
@d.select(Sequel.function(:test, :abc, 'hello')).sql.must_equal "SELECT test(`abc`, 'hello') FROM `items`"
|
186
|
-
@d.select(Sequel.function(:test, :
|
187
|
-
@d.select(Sequel.function(:test, :
|
186
|
+
@d.select(Sequel.function(:test, Sequel[:abc][:def], 'hello')).sql.must_equal "SELECT test(`abc`.`def`, 'hello') FROM `items`"
|
187
|
+
@d.select(Sequel.function(:test, Sequel[:abc][:def], 'hello').as(:x2)).sql.must_equal "SELECT test(`abc`.`def`, 'hello') AS `x2` FROM `items`"
|
188
188
|
@d.insert_sql(:value => 333).must_equal 'INSERT INTO `items` (`value`) VALUES (333)'
|
189
189
|
@d.insert_sql(:x => :y).must_equal 'INSERT INTO `items` (`x`) VALUES (`y`)'
|
190
190
|
end
|
@@ -1324,13 +1324,13 @@ describe "MySQL joined datasets" do
|
|
1324
1324
|
end
|
1325
1325
|
|
1326
1326
|
it "should support deletions from a single table" do
|
1327
|
-
@ds.where(:
|
1327
|
+
@ds.where(Sequel[:a][:id]=>1).delete
|
1328
1328
|
@db[:a].select_order_map(:id).must_equal [2]
|
1329
1329
|
@db[:b].select_order_map(:id).must_equal [3, 4, 5]
|
1330
1330
|
end
|
1331
1331
|
|
1332
1332
|
it "should support deletions from multiple tables" do
|
1333
|
-
@ds.delete_from(:a, :b).where(:
|
1333
|
+
@ds.delete_from(:a, :b).where(Sequel[:a][:id]=>1).delete
|
1334
1334
|
@db[:a].select_order_map(:id).must_equal [2]
|
1335
1335
|
@db[:b].select_order_map(:id).must_equal [5]
|
1336
1336
|
end
|
@@ -263,25 +263,25 @@ describe "An Oracle database" do
|
|
263
263
|
@d2 << {:id => 100, :cat_name => 'ruby'}
|
264
264
|
@d2 << {:id => 101, :cat_name => 'rails'}
|
265
265
|
|
266
|
-
@d1.join(:categories, :id => :category_id).select(:
|
266
|
+
@d1.join(:categories, :id => :category_id).select(Sequel[:books][:id], :title, :cat_name).order(Sequel[:books][:id]).to_a.must_equal [
|
267
267
|
{:id => 1, :title => 'aaa', :cat_name => 'ruby'},
|
268
268
|
{:id => 2, :title => 'bbb', :cat_name => 'ruby'},
|
269
269
|
{:id => 3, :title => 'ccc', :cat_name => 'rails'}
|
270
270
|
]
|
271
271
|
|
272
|
-
@d1.join(:categories, :id => :category_id).select(:
|
272
|
+
@d1.join(:categories, :id => :category_id).select(Sequel[:books][:id], :title, :cat_name).order(Sequel[:books][:id]).limit(2, 1).to_a.must_equal [
|
273
273
|
{:id => 2, :title => 'bbb', :cat_name => 'ruby'},
|
274
274
|
{:id => 3, :title => 'ccc', :cat_name => 'rails'},
|
275
275
|
]
|
276
276
|
|
277
|
-
@d1.left_outer_join(:categories, :id => :category_id).select(:
|
277
|
+
@d1.left_outer_join(:categories, :id => :category_id).select(Sequel[:books][:id], :title, :cat_name).order(Sequel[:books][:id]).to_a.must_equal [
|
278
278
|
{:id => 1, :title => 'aaa', :cat_name => 'ruby'},
|
279
279
|
{:id => 2, :title => 'bbb', :cat_name => 'ruby'},
|
280
280
|
{:id => 3, :title => 'ccc', :cat_name => 'rails'},
|
281
281
|
{:id => 4, :title => 'ddd', :cat_name => nil}
|
282
282
|
]
|
283
283
|
|
284
|
-
@d1.left_outer_join(:categories, :id => :category_id).select(:
|
284
|
+
@d1.left_outer_join(:categories, :id => :category_id).select(Sequel[:books][:id], :title, :cat_name).reverse_order(Sequel[:books][:id]).limit(2, 0).to_a.must_equal [
|
285
285
|
{:id => 4, :title => 'ddd', :cat_name => nil},
|
286
286
|
{:id => 3, :title => 'ccc', :cat_name => 'rails'}
|
287
287
|
]
|
@@ -121,11 +121,11 @@ describe "PostgreSQL", '#create_table' do
|
|
121
121
|
@db.create_table(:tmp_dolls){text :name}
|
122
122
|
@db.loose_count(:tmp_dolls).must_be_kind_of(Integer)
|
123
123
|
@db.loose_count(:tmp_dolls).must_equal 0
|
124
|
-
@db.loose_count(:
|
124
|
+
@db.loose_count(Sequel[:public][:tmp_dolls]).must_equal 0
|
125
125
|
@db[:tmp_dolls].insert('a')
|
126
126
|
@db << 'VACUUM ANALYZE tmp_dolls'
|
127
127
|
@db.loose_count(:tmp_dolls).must_equal 1
|
128
|
-
@db.loose_count(:
|
128
|
+
@db.loose_count(Sequel[:public][:tmp_dolls]).must_equal 1
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -184,7 +184,7 @@ end
|
|
184
184
|
describe "PostgreSQL", 'INSERT ON CONFLICT' do
|
185
185
|
before(:all) do
|
186
186
|
@db = DB
|
187
|
-
@db.create_table!(:ic_test){Integer :a; Integer :b; Integer :c; unique :a, :name=>:ic_test_a_uidx; unique [:b, :c], :name=>:ic_test_b_c_uidx}
|
187
|
+
@db.create_table!(:ic_test){Integer :a; Integer :b; Integer :c; TrueClass :c_is_unique, :default=>false; unique :a, :name=>:ic_test_a_uidx; unique [:b, :c], :name=>:ic_test_b_c_uidx; index [:c], :where=>:c_is_unique, :unique=>true}
|
188
188
|
@ds = @db[:ic_test]
|
189
189
|
end
|
190
190
|
before do
|
@@ -196,41 +196,46 @@ describe "PostgreSQL", 'INSERT ON CONFLICT' do
|
|
196
196
|
|
197
197
|
it "Dataset#insert_ignore and insert_conflict should ignore uniqueness violations" do
|
198
198
|
@ds.insert(1, 2, 3)
|
199
|
+
@ds.insert(10, 11, 3, true)
|
199
200
|
proc{@ds.insert(1, 3, 4)}.must_raise Sequel::UniqueConstraintViolation
|
201
|
+
proc{@ds.insert(11, 12, 3, true)}.must_raise Sequel::UniqueConstraintViolation
|
200
202
|
@ds.insert_ignore.insert(1, 3, 4).must_equal nil
|
201
203
|
@ds.insert_conflict.insert(1, 3, 4).must_equal nil
|
204
|
+
@ds.insert_conflict.insert(11, 12, 3, true).must_equal nil
|
202
205
|
@ds.insert_conflict(:target=>:a).insert(1, 3, 4).must_equal nil
|
206
|
+
@ds.insert_conflict(:target=>:c, :conflict_where=>:c_is_unique).insert(11, 12, 3, true).must_equal nil
|
203
207
|
@ds.insert_conflict(:constraint=>:ic_test_a_uidx).insert(1, 3, 4).must_equal nil
|
204
|
-
@ds.all.must_equal [{:a=>1, :b=>2, :c=>3}]
|
208
|
+
@ds.all.must_equal [{:a=>1, :b=>2, :c=>3, :c_is_unique=>false}, {:a=>10, :b=>11, :c=>3, :c_is_unique=>true}]
|
205
209
|
end
|
206
210
|
|
207
211
|
it "Dataset#insert_ignore and insert_conflict should work with multi_insert/import" do
|
208
212
|
@ds.insert(1, 2, 3)
|
209
213
|
@ds.insert_ignore.multi_insert([{:a=>1, :b=>3, :c=>4}])
|
210
214
|
@ds.insert_ignore.import([:a, :b, :c], [[1, 3, 4]])
|
211
|
-
@ds.all.must_equal [{:a=>1, :b=>2, :c=>3}]
|
215
|
+
@ds.all.must_equal [{:a=>1, :b=>2, :c=>3, :c_is_unique=>false}]
|
212
216
|
@ds.insert_conflict(:target=>:a, :update=>{:b=>3}).import([:a, :b, :c], [[1, 3, 4]])
|
213
|
-
@ds.all.must_equal [{:a=>1, :b=>3, :c=>3}]
|
217
|
+
@ds.all.must_equal [{:a=>1, :b=>3, :c=>3, :c_is_unique=>false}]
|
214
218
|
@ds.insert_conflict(:target=>:a, :update=>{:b=>4}).multi_insert([{:a=>1, :b=>5, :c=>6}])
|
215
|
-
@ds.all.must_equal [{:a=>1, :b=>4, :c=>3}]
|
219
|
+
@ds.all.must_equal [{:a=>1, :b=>4, :c=>3, :c_is_unique=>false}]
|
216
220
|
end
|
217
221
|
|
218
222
|
it "Dataset#insert_conflict should handle upserts" do
|
219
223
|
@ds.insert(1, 2, 3)
|
220
224
|
@ds.insert_conflict(:target=>:a, :update=>{:b=>3}).insert(1, 3, 4).must_equal nil
|
221
|
-
@ds.all.must_equal [{:a=>1, :b=>3, :c=>3}]
|
225
|
+
@ds.all.must_equal [{:a=>1, :b=>3, :c=>3, :c_is_unique=>false}]
|
222
226
|
@ds.insert_conflict(:target=>[:b, :c], :update=>{:c=>5}).insert(5, 3, 3).must_equal nil
|
223
|
-
@ds.all.must_equal [{:a=>1, :b=>3, :c=>5}]
|
227
|
+
@ds.all.must_equal [{:a=>1, :b=>3, :c=>5, :c_is_unique=>false}]
|
224
228
|
@ds.insert_conflict(:constraint=>:ic_test_a_uidx, :update=>{:b=>4}).insert(1, 3).must_equal nil
|
225
|
-
@ds.all.must_equal [{:a=>1, :b=>4, :c=>5}]
|
226
|
-
@ds.insert_conflict(:constraint=>:ic_test_a_uidx, :update=>{:b=>5}, :update_where=>{:
|
227
|
-
@ds.all.must_equal [{:a=>1, :b=>5, :c=>5}]
|
228
|
-
@ds.insert_conflict(:constraint=>:ic_test_a_uidx, :update=>{:b=>6}, :update_where=>{:
|
229
|
-
@ds.all.must_equal [{:a=>1, :b=>5, :c=>5}]
|
229
|
+
@ds.all.must_equal [{:a=>1, :b=>4, :c=>5, :c_is_unique=>false}]
|
230
|
+
@ds.insert_conflict(:constraint=>:ic_test_a_uidx, :update=>{:b=>5}, :update_where=>{Sequel[:ic_test][:b]=>4}).insert(1, 3, 4).must_equal nil
|
231
|
+
@ds.all.must_equal [{:a=>1, :b=>5, :c=>5, :c_is_unique=>false}]
|
232
|
+
@ds.insert_conflict(:constraint=>:ic_test_a_uidx, :update=>{:b=>6}, :update_where=>{Sequel[:ic_test][:b]=>4}).insert(1, 3, 4).must_equal nil
|
233
|
+
@ds.all.must_equal [{:a=>1, :b=>5, :c=>5, :c_is_unique=>false}]
|
230
234
|
end
|
231
235
|
|
232
236
|
it "Dataset#insert_conflict should respect expressions in the target argument" do
|
233
237
|
@ds.insert_conflict(:target=>:a).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"a\") DO NOTHING"
|
238
|
+
@ds.insert_conflict(:target=>:c, :conflict_where=>{:c_is_unique=>true}).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"c\") WHERE (\"c_is_unique\" IS TRUE) DO NOTHING"
|
234
239
|
@ds.insert_conflict(:target=>[:b, :c]).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"b\", \"c\") DO NOTHING"
|
235
240
|
@ds.insert_conflict(:target=>[:b, Sequel.function(:round, :c)]).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"b\", round(\"c\")) DO NOTHING"
|
236
241
|
@ds.insert_conflict(:target=>[:b, Sequel.virtual_row{|o| o.round(:c)}]).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"b\", round(\"c\")) DO NOTHING"
|
@@ -240,10 +245,10 @@ end if DB.server_version >= 90500
|
|
240
245
|
describe "A PostgreSQL database" do
|
241
246
|
before(:all) do
|
242
247
|
@db = DB
|
243
|
-
@db.create_table!(:
|
248
|
+
@db.create_table!(Sequel[:public][:testfk]){primary_key :id; foreign_key :i, Sequel[:public][:testfk]}
|
244
249
|
end
|
245
250
|
after(:all) do
|
246
|
-
@db.drop_table?(:
|
251
|
+
@db.drop_table?(Sequel[:public][:testfk])
|
247
252
|
end
|
248
253
|
|
249
254
|
it "should provide the server version" do
|
@@ -268,16 +273,16 @@ describe "A PostgreSQL database" do
|
|
268
273
|
end
|
269
274
|
|
270
275
|
it "should respect the :read_only option per-savepoint" do
|
271
|
-
proc{@db.transaction{@db.transaction(:savepoint=>true, :read_only=>true){@db[:
|
272
|
-
proc{@db.transaction(:auto_savepoint=>true, :read_only=>true){@db.transaction(:read_only=>false){@db[:
|
273
|
-
@db[:
|
274
|
-
@db.transaction{@db[:
|
275
|
-
@db.transaction{@db.transaction(:savepoint=>true, :read_only=>true){}; @db[:
|
276
|
-
@db.transaction{@db[:
|
276
|
+
proc{@db.transaction{@db.transaction(:savepoint=>true, :read_only=>true){@db[Sequel[:public][:testfk]].insert}}}.must_raise(Sequel::DatabaseError)
|
277
|
+
proc{@db.transaction(:auto_savepoint=>true, :read_only=>true){@db.transaction(:read_only=>false){@db[Sequel[:public][:testfk]].insert}}}.must_raise(Sequel::DatabaseError)
|
278
|
+
@db[Sequel[:public][:testfk]].delete
|
279
|
+
@db.transaction{@db[Sequel[:public][:testfk]].insert; @db.transaction(:savepoint=>true, :read_only=>true){@db[Sequel[:public][:testfk]].all;}}
|
280
|
+
@db.transaction{@db.transaction(:savepoint=>true, :read_only=>true){}; @db[Sequel[:public][:testfk]].insert}
|
281
|
+
@db.transaction{@db[Sequel[:public][:testfk]].all; @db.transaction(:savepoint=>true, :read_only=>true){@db[Sequel[:public][:testfk]].all;}}
|
277
282
|
end
|
278
283
|
|
279
284
|
it "should support disable_insert_returning" do
|
280
|
-
ds = @db[:
|
285
|
+
ds = @db[Sequel[:public][:testfk]].disable_insert_returning
|
281
286
|
ds.delete
|
282
287
|
ds.insert.must_equal nil
|
283
288
|
id = ds.max(:id)
|
@@ -299,26 +304,32 @@ describe "A PostgreSQL database" do
|
|
299
304
|
end
|
300
305
|
|
301
306
|
it "should support functions with and without quoting" do
|
302
|
-
ds = @db[:
|
307
|
+
ds = @db[Sequel[:public][:testfk]]
|
303
308
|
ds.delete
|
304
309
|
ds.insert
|
305
310
|
ds.get{sum(1)}.must_equal 1
|
306
311
|
ds.get{Sequel.function('pg_catalog.sum', 1)}.must_equal 1
|
307
312
|
ds.get{sum.function(1)}.must_equal 1
|
308
|
-
ds.get{
|
313
|
+
ds.get{pg_catalog[:sum].function(1)}.must_equal 1
|
309
314
|
ds.delete
|
310
315
|
end
|
311
316
|
|
312
317
|
it "should support a :qualify option to tables and views" do
|
313
|
-
@db.tables(:qualify=>true).must_include(Sequel.qualify(
|
318
|
+
@db.tables(:qualify=>true).must_include(Sequel.qualify('public', 'testfk'))
|
314
319
|
begin
|
315
320
|
@db.create_view(:testfkv, @db[:testfk])
|
316
|
-
@db.views(:qualify=>true).must_include(Sequel.qualify(
|
321
|
+
@db.views(:qualify=>true).must_include(Sequel.qualify('public', 'testfkv'))
|
317
322
|
ensure
|
318
323
|
@db.drop_view(:testfkv)
|
319
324
|
end
|
320
325
|
end
|
321
326
|
|
327
|
+
it "should handle double underscores in tables when using the qualify option" do
|
328
|
+
@db.create_table!(Sequel.qualify(:public, 'test__fk')){Integer :a}
|
329
|
+
@db.tables(:qualify=>true).must_include(Sequel.qualify('public', 'test__fk'))
|
330
|
+
@db.drop_table(Sequel.qualify(:public, 'test__fk'))
|
331
|
+
end
|
332
|
+
|
322
333
|
it "should not typecast the int2vector type incorrectly" do
|
323
334
|
@db.get(Sequel.cast('10 20', :int2vector)).wont_equal 10
|
324
335
|
end
|
@@ -328,11 +339,11 @@ describe "A PostgreSQL database" do
|
|
328
339
|
end
|
329
340
|
|
330
341
|
it "should correctly parse the schema" do
|
331
|
-
@db.schema(:
|
342
|
+
@db.schema(Sequel[:public][:testfk], :reload=>true).map{|c,s| [c, s[:oid]]}.must_equal [[:id, 23], [:i, 23]]
|
332
343
|
end
|
333
344
|
|
334
345
|
it "should parse foreign keys for tables in a schema" do
|
335
|
-
@db.foreign_key_list(:
|
346
|
+
@db.foreign_key_list(Sequel[:public][:testfk]).must_equal [{:on_delete=>:no_action, :on_update=>:no_action, :columns=>[:i], :key=>[:id], :deferrable=>false, :table=>Sequel.qualify(:public, :testfk), :name=>:testfk_i_fkey}]
|
336
347
|
end
|
337
348
|
|
338
349
|
it "should return uuid fields as strings" do
|
@@ -405,7 +416,7 @@ describe "A PostgreSQL dataset" do
|
|
405
416
|
@d.select(Sequel.lit('COUNT(*)')).sql.must_equal 'SELECT COUNT(*) FROM "test"'
|
406
417
|
@d.select(Sequel.function(:max, :value)).sql.must_equal 'SELECT max("value") FROM "test"'
|
407
418
|
@d.select(Sequel.function(:NOW)).sql.must_equal 'SELECT NOW() FROM "test"'
|
408
|
-
@d.select(Sequel.function(:max, :
|
419
|
+
@d.select(Sequel.function(:max, Sequel[:items][:value])).sql.must_equal 'SELECT max("items"."value") FROM "test"'
|
409
420
|
@d.order(Sequel.desc(:name)).sql.must_equal 'SELECT * FROM "test" ORDER BY "name" DESC'
|
410
421
|
@d.select(Sequel.lit('test.name AS item_name')).sql.must_equal 'SELECT test.name AS item_name FROM "test"'
|
411
422
|
@d.select(Sequel.lit('"name"')).sql.must_equal 'SELECT "name" FROM "test"'
|
@@ -413,8 +424,8 @@ describe "A PostgreSQL dataset" do
|
|
413
424
|
@d.insert_sql(:x => :y).must_match(/\AINSERT INTO "test" \("x"\) VALUES \("y"\)( RETURNING NULL)?\z/)
|
414
425
|
|
415
426
|
@d.select(Sequel.function(:test, :abc, 'hello')).sql.must_equal "SELECT test(\"abc\", 'hello') FROM \"test\""
|
416
|
-
@d.select(Sequel.function(:test, :
|
417
|
-
@d.select(Sequel.function(:test, :
|
427
|
+
@d.select(Sequel.function(:test, Sequel[:abc][:def], 'hello')).sql.must_equal "SELECT test(\"abc\".\"def\", 'hello') FROM \"test\""
|
428
|
+
@d.select(Sequel.function(:test, Sequel[:abc][:def], 'hello').as(:x2)).sql.must_equal "SELECT test(\"abc\".\"def\", 'hello') AS \"x2\" FROM \"test\""
|
418
429
|
@d.insert_sql(:value => 333).must_match(/\AINSERT INTO "test" \("value"\) VALUES \(333\)( RETURNING NULL)?\z/)
|
419
430
|
end
|
420
431
|
end
|
@@ -1154,13 +1165,13 @@ describe "Postgres::Dataset#insert" do
|
|
1154
1165
|
end
|
1155
1166
|
|
1156
1167
|
it "should have insert_select respect existing returning clause" do
|
1157
|
-
h = @ds.returning(:
|
1168
|
+
h = @ds.returning(Sequel[:value].as(:v), Sequel[:xid].as(:x)).insert_select(:value=>10)
|
1158
1169
|
h[:v].must_equal 10
|
1159
1170
|
@ds.first(:xid=>h[:x])[:value].must_equal 10
|
1160
1171
|
end
|
1161
1172
|
|
1162
1173
|
it "should have prepared insert_select respect existing returning clause" do
|
1163
|
-
h = @ds.returning(:
|
1174
|
+
h = @ds.returning(Sequel[:value].as(:v), Sequel[:xid].as(:x)).prepare(:insert_select, :insert_select, :value=>10).call
|
1164
1175
|
h[:v].must_equal 10
|
1165
1176
|
@ds.first(:xid=>h[:x])[:value].must_equal 10
|
1166
1177
|
end
|
@@ -1193,33 +1204,33 @@ describe "Postgres::Database schema qualified tables" do
|
|
1193
1204
|
end
|
1194
1205
|
|
1195
1206
|
it "should be able to create, drop, select and insert into tables in a given schema" do
|
1196
|
-
@db.create_table(:
|
1197
|
-
@db[:
|
1198
|
-
@db[:
|
1199
|
-
@db[:
|
1207
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){primary_key :i}
|
1208
|
+
@db[Sequel[:schema_test][:schema_test]].first.must_equal nil
|
1209
|
+
@db[Sequel[:schema_test][:schema_test]].insert(:i=>1).must_equal 1
|
1210
|
+
@db[Sequel[:schema_test][:schema_test]].first.must_equal(:i=>1)
|
1200
1211
|
@db.from(Sequel.lit('schema_test.schema_test')).first.must_equal(:i=>1)
|
1201
|
-
@db.drop_table(:
|
1212
|
+
@db.drop_table(Sequel[:schema_test][:schema_test])
|
1202
1213
|
@db.create_table(Sequel.qualify(:schema_test, :schema_test)){integer :i}
|
1203
|
-
@db[:
|
1214
|
+
@db[Sequel[:schema_test][:schema_test]].first.must_equal nil
|
1204
1215
|
@db.from(Sequel.lit('schema_test.schema_test')).first.must_equal nil
|
1205
1216
|
@db.drop_table(Sequel.qualify(:schema_test, :schema_test))
|
1206
1217
|
end
|
1207
1218
|
|
1208
1219
|
it "#tables should not include tables in a default non-public schema" do
|
1209
|
-
@db.create_table(:
|
1220
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){integer :i}
|
1210
1221
|
@db.tables(:schema=>:schema_test).must_include(:schema_test)
|
1211
1222
|
@db.tables.wont_include(:pg_am)
|
1212
1223
|
@db.tables.wont_include(:domain_udt_usage)
|
1213
1224
|
end
|
1214
1225
|
|
1215
1226
|
it "#tables should return tables in the schema provided by the :schema argument" do
|
1216
|
-
@db.create_table(:
|
1227
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){integer :i}
|
1217
1228
|
@db.tables(:schema=>:schema_test).must_equal [:schema_test]
|
1218
1229
|
end
|
1219
1230
|
|
1220
1231
|
it "#schema should not include columns from tables in a default non-public schema" do
|
1221
|
-
@db.create_table(:
|
1222
|
-
sch = @db.schema(:
|
1232
|
+
@db.create_table(Sequel[:schema_test][:domains]){integer :i}
|
1233
|
+
sch = @db.schema(Sequel[:schema_test][:domains])
|
1223
1234
|
cs = sch.map{|x| x.first}
|
1224
1235
|
cs.must_include(:i)
|
1225
1236
|
cs.wont_include(:data_type)
|
@@ -1227,7 +1238,7 @@ describe "Postgres::Database schema qualified tables" do
|
|
1227
1238
|
|
1228
1239
|
it "#schema should only include columns from the table in the given :schema argument" do
|
1229
1240
|
@db.create_table!(:domains){integer :d}
|
1230
|
-
@db.create_table(:
|
1241
|
+
@db.create_table(Sequel[:schema_test][:domains]){integer :i}
|
1231
1242
|
sch = @db.schema(:domains, :schema=>:schema_test)
|
1232
1243
|
cs = sch.map{|x| x.first}
|
1233
1244
|
cs.must_include(:i)
|
@@ -1236,64 +1247,64 @@ describe "Postgres::Database schema qualified tables" do
|
|
1236
1247
|
end
|
1237
1248
|
|
1238
1249
|
it "#schema should not include columns in tables from other domains by default" do
|
1239
|
-
@db.create_table!(:
|
1240
|
-
@db.create_table(:
|
1250
|
+
@db.create_table!(Sequel[:public][:domains]){integer :d}
|
1251
|
+
@db.create_table(Sequel[:schema_test][:domains]){integer :i}
|
1241
1252
|
begin
|
1242
1253
|
@db.schema(:domains).map{|x| x.first}.must_equal [:d]
|
1243
|
-
@db.schema(:
|
1254
|
+
@db.schema(Sequel[:schema_test][:domains]).map{|x| x.first}.must_equal [:i]
|
1244
1255
|
ensure
|
1245
|
-
@db.drop_table?(:
|
1256
|
+
@db.drop_table?(Sequel[:public][:domains])
|
1246
1257
|
end
|
1247
1258
|
end
|
1248
1259
|
|
1249
1260
|
it "#table_exists? should see if the table is in a given schema" do
|
1250
|
-
@db.create_table(:
|
1251
|
-
@db.table_exists?(:
|
1261
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){integer :i}
|
1262
|
+
@db.table_exists?(Sequel[:schema_test][:schema_test]).must_equal true
|
1252
1263
|
end
|
1253
1264
|
|
1254
1265
|
it "should be able to add and drop indexes in a schema" do
|
1255
|
-
@db.create_table(:
|
1256
|
-
@db.indexes(:
|
1257
|
-
@db.drop_index :
|
1258
|
-
@db.indexes(:
|
1266
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){Integer :i, :index=>true}
|
1267
|
+
@db.indexes(Sequel[:schema_test][:schema_test]).keys.must_equal [:schema_test_schema_test_i_index]
|
1268
|
+
@db.drop_index Sequel[:schema_test][:schema_test], :i
|
1269
|
+
@db.indexes(Sequel[:schema_test][:schema_test]).keys.must_equal []
|
1259
1270
|
end
|
1260
1271
|
|
1261
1272
|
it "should be able to get primary keys for tables in a given schema" do
|
1262
|
-
@db.create_table(:
|
1263
|
-
@db.primary_key(:
|
1273
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){primary_key :i}
|
1274
|
+
@db.primary_key(Sequel[:schema_test][:schema_test]).must_equal 'i'
|
1264
1275
|
end
|
1265
1276
|
|
1266
1277
|
it "should be able to get serial sequences for tables in a given schema" do
|
1267
|
-
@db.create_table(:
|
1268
|
-
@db.primary_key_sequence(:
|
1278
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){primary_key :i}
|
1279
|
+
@db.primary_key_sequence(Sequel[:schema_test][:schema_test]).must_equal '"schema_test"."schema_test_i_seq"'
|
1269
1280
|
end
|
1270
1281
|
|
1271
1282
|
it "should be able to get serial sequences for tables that have spaces in the name in a given schema" do
|
1272
|
-
@db.create_table(:"
|
1273
|
-
@db.primary_key_sequence(:"
|
1283
|
+
@db.create_table(Sequel[:schema_test][:"schema test"]){primary_key :i}
|
1284
|
+
@db.primary_key_sequence(Sequel[:schema_test][:"schema test"]).must_equal '"schema_test"."schema test_i_seq"'
|
1274
1285
|
end
|
1275
1286
|
|
1276
1287
|
it "should be able to get custom sequences for tables in a given schema" do
|
1277
1288
|
@db << "CREATE SEQUENCE schema_test.kseq"
|
1278
|
-
@db.create_table(:
|
1279
|
-
@db.primary_key_sequence(:
|
1289
|
+
@db.create_table(Sequel[:schema_test][:schema_test]){integer :j; primary_key :k, :type=>:integer, :default=>Sequel.lit("nextval('schema_test.kseq'::regclass)")}
|
1290
|
+
@db.primary_key_sequence(Sequel[:schema_test][:schema_test]).must_equal '"schema_test".kseq'
|
1280
1291
|
end
|
1281
1292
|
|
1282
1293
|
it "should be able to get custom sequences for tables that have spaces in the name in a given schema" do
|
1283
1294
|
@db << "CREATE SEQUENCE schema_test.\"ks eq\""
|
1284
|
-
@db.create_table(:"
|
1285
|
-
@db.primary_key_sequence(:"
|
1295
|
+
@db.create_table(Sequel[:schema_test][:"schema test"]){integer :j; primary_key :k, :type=>:integer, :default=>Sequel.lit("nextval('schema_test.\"ks eq\"'::regclass)")}
|
1296
|
+
@db.primary_key_sequence(Sequel[:schema_test][:"schema test"]).must_equal '"schema_test"."ks eq"'
|
1286
1297
|
end
|
1287
1298
|
|
1288
1299
|
it "should handle schema introspection cases with tables with same name in multiple schemas" do
|
1289
1300
|
begin
|
1290
|
-
@db.create_table(:
|
1301
|
+
@db.create_table(Sequel[:schema_test][:schema_test]) do
|
1291
1302
|
primary_key :id
|
1292
|
-
foreign_key :i, :
|
1303
|
+
foreign_key :i, Sequel[:schema_test][:schema_test], :index=>{:name=>:schema_test_sti}
|
1293
1304
|
end
|
1294
|
-
@db.create_table!(:
|
1305
|
+
@db.create_table!(Sequel[:public][:schema_test]) do
|
1295
1306
|
primary_key :id
|
1296
|
-
foreign_key :j, :
|
1307
|
+
foreign_key :j, Sequel[:public][:schema_test], :index=>{:name=>:public_test_sti}
|
1297
1308
|
end
|
1298
1309
|
|
1299
1310
|
h = @db.schema(:schema_test)
|
@@ -1303,7 +1314,7 @@ describe "Postgres::Database schema qualified tables" do
|
|
1303
1314
|
@db.indexes(:schema_test).must_equal(:public_test_sti=>{:unique=>false, :columns=>[:j], :deferrable=>nil})
|
1304
1315
|
@db.foreign_key_list(:schema_test).must_equal [{:on_update=>:no_action, :columns=>[:j], :deferrable=>false, :key=>[:id], :table=>:schema_test, :on_delete=>:no_action, :name=>:schema_test_j_fkey}]
|
1305
1316
|
ensure
|
1306
|
-
@db.drop_table?(:
|
1317
|
+
@db.drop_table?(Sequel[:public][:schema_test])
|
1307
1318
|
end
|
1308
1319
|
end
|
1309
1320
|
end
|
@@ -1314,15 +1325,15 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1314
1325
|
@db.run "DROP SCHEMA s CASCADE" rescue nil
|
1315
1326
|
@db.run "CREATE SCHEMA s"
|
1316
1327
|
|
1317
|
-
@db.create_table(:
|
1318
|
-
@db.create_table(:
|
1319
|
-
@db.create_table(:
|
1320
|
-
@db.create_table(:
|
1328
|
+
@db.create_table(Sequel[:s][:bands]){primary_key :id; String :name}
|
1329
|
+
@db.create_table(Sequel[:s][:albums]){primary_key :id; String :name; foreign_key :band_id, Sequel[:s][:bands]}
|
1330
|
+
@db.create_table(Sequel[:s][:tracks]){primary_key :id; String :name; foreign_key :album_id, Sequel[:s][:albums]}
|
1331
|
+
@db.create_table(Sequel[:s][:members]){primary_key :id; String :name; foreign_key :band_id, Sequel[:s][:bands]}
|
1321
1332
|
|
1322
|
-
@Band = Class.new(Sequel::Model(:
|
1323
|
-
@Album = Class.new(Sequel::Model(:
|
1324
|
-
@Track = Class.new(Sequel::Model(:
|
1325
|
-
@Member = Class.new(Sequel::Model(:
|
1333
|
+
@Band = Class.new(Sequel::Model(Sequel[:s][:bands]))
|
1334
|
+
@Album = Class.new(Sequel::Model(Sequel[:s][:albums]))
|
1335
|
+
@Track = Class.new(Sequel::Model(Sequel[:s][:tracks]))
|
1336
|
+
@Member = Class.new(Sequel::Model(Sequel[:s][:members]))
|
1326
1337
|
def @Band.name; :Band; end
|
1327
1338
|
def @Album.name; :Album; end
|
1328
1339
|
def @Track.name; :Track; end
|
@@ -1335,8 +1346,8 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1335
1346
|
@Track.many_to_one :album, :class=>@Album, :order=>:name
|
1336
1347
|
@Member.many_to_one :band, :class=>@Band, :order=>:name
|
1337
1348
|
|
1338
|
-
@Member.many_to_many :members, :class=>@Member, :join_table
|
1339
|
-
@Band.many_to_many :tracks, :class=>@Track, :join_table
|
1349
|
+
@Member.many_to_many :members, :class=>@Member, :join_table=>Sequel[:s][:bands], :right_key=>:id, :left_key=>:id, :left_primary_key=>:band_id, :right_primary_key=>:band_id, :order=>:name
|
1350
|
+
@Band.many_to_many :tracks, :class=>@Track, :join_table=>Sequel[:s][:albums], :right_key=>:id, :right_primary_key=>:album_id, :order=>:name
|
1340
1351
|
|
1341
1352
|
@b1 = @Band.create(:name=>"BM")
|
1342
1353
|
@b2 = @Band.create(:name=>"J")
|
@@ -1358,16 +1369,16 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1358
1369
|
end
|
1359
1370
|
|
1360
1371
|
it "should return all eager graphs correctly" do
|
1361
|
-
bands = @Band.order(:
|
1372
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:albums).all
|
1362
1373
|
bands.must_equal [@b1, @b2]
|
1363
1374
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1364
1375
|
|
1365
|
-
bands = @Band.order(:
|
1376
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:albums=>:tracks).all
|
1366
1377
|
bands.must_equal [@b1, @b2]
|
1367
1378
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1368
1379
|
bands.map{|x| x.albums.map{|y| y.tracks}}.must_equal [[[@t1, @t2], [@t3, @t4]], [[], []]]
|
1369
1380
|
|
1370
|
-
bands = @Band.order(:
|
1381
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph({:albums=>:tracks}, :members).all
|
1371
1382
|
bands.must_equal [@b1, @b2]
|
1372
1383
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1373
1384
|
bands.map{|x| x.albums.map{|y| y.tracks}}.must_equal [[[@t1, @t2], [@t3, @t4]], [[], []]]
|
@@ -1375,14 +1386,14 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1375
1386
|
end
|
1376
1387
|
|
1377
1388
|
it "should have eager graphs work with previous joins" do
|
1378
|
-
bands = @Band.order(:
|
1389
|
+
bands = @Band.order(Sequel[:bands][:name]).select_all(Sequel[:s][:bands]).join(Sequel[:s][:members], :band_id=>:id).from_self(:alias=>:bands0).eager_graph(:albums=>:tracks).all
|
1379
1390
|
bands.must_equal [@b1, @b2]
|
1380
1391
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1381
1392
|
bands.map{|x| x.albums.map{|y| y.tracks}}.must_equal [[[@t1, @t2], [@t3, @t4]], [[], []]]
|
1382
1393
|
end
|
1383
1394
|
|
1384
1395
|
it "should have eager graphs work with joins with the same tables" do
|
1385
|
-
bands = @Band.order(:
|
1396
|
+
bands = @Band.order(Sequel[:bands][:name]).select_all(Sequel[:s][:bands]).join(Sequel[:s][:members], :band_id=>:id).eager_graph({:albums=>:tracks}, :members).all
|
1386
1397
|
bands.must_equal [@b1, @b2]
|
1387
1398
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1388
1399
|
bands.map{|x| x.albums.map{|y| y.tracks}}.must_equal [[[@t1, @t2], [@t3, @t4]], [[], []]]
|
@@ -1390,17 +1401,17 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1390
1401
|
end
|
1391
1402
|
|
1392
1403
|
it "should have eager graphs work with self referential associations" do
|
1393
|
-
bands = @Band.order(:
|
1404
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:tracks=>{:album=>:band}).all
|
1394
1405
|
bands.must_equal [@b1, @b2]
|
1395
1406
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1396
1407
|
bands.map{|x| x.tracks.map{|y| y.album}}.must_equal [[@a1, @a1, @a2, @a2], []]
|
1397
1408
|
bands.map{|x| x.tracks.map{|y| y.album.band}}.must_equal [[@b1, @b1, @b1, @b1], []]
|
1398
1409
|
|
1399
|
-
members = @Member.order(:
|
1410
|
+
members = @Member.order(Sequel[:members][:name]).eager_graph(:members).all
|
1400
1411
|
members.must_equal [@m4, @m3, @m1, @m2]
|
1401
1412
|
members.map{|x| x.members}.must_equal [[@m4, @m3], [@m4, @m3], [@m1, @m2], [@m1, @m2]]
|
1402
1413
|
|
1403
|
-
members = @Member.order(:
|
1414
|
+
members = @Member.order(Sequel[:members][:name]).eager_graph(:band, :members=>:band).all
|
1404
1415
|
members.must_equal [@m4, @m3, @m1, @m2]
|
1405
1416
|
members.map{|x| x.band}.must_equal [@b2, @b2, @b1, @b1]
|
1406
1417
|
members.map{|x| x.members}.must_equal [[@m4, @m3], [@m4, @m3], [@m1, @m2], [@m1, @m2]]
|
@@ -1408,7 +1419,7 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1408
1419
|
end
|
1409
1420
|
|
1410
1421
|
it "should have eager graphs work with a from_self dataset" do
|
1411
|
-
bands = @Band.order(:
|
1422
|
+
bands = @Band.order(Sequel[:bands][:name]).from_self.eager_graph(:tracks=>{:album=>:band}).all
|
1412
1423
|
bands.must_equal [@b1, @b2]
|
1413
1424
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1414
1425
|
bands.map{|x| x.tracks.map{|y| y.album}}.must_equal [[@a1, @a1, @a2, @a2], []]
|
@@ -1416,70 +1427,70 @@ describe "Postgres::Database schema qualified tables and eager graphing" do
|
|
1416
1427
|
end
|
1417
1428
|
|
1418
1429
|
it "should have eager graphs work with different types of aliased from tables" do
|
1419
|
-
bands = @Band.order(:
|
1430
|
+
bands = @Band.order(Sequel[:tracks][:name]).from(Sequel[:s][:bands].as(:tracks)).eager_graph(:tracks).all
|
1420
1431
|
bands.must_equal [@b1, @b2]
|
1421
1432
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1422
1433
|
|
1423
|
-
bands = @Band.order(:
|
1434
|
+
bands = @Band.order(Sequel[:tracks][:name]).from(Sequel.expr(Sequel[:s][:bands]).as(:tracks)).eager_graph(:tracks).all
|
1424
1435
|
bands.must_equal [@b1, @b2]
|
1425
1436
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1426
1437
|
|
1427
|
-
bands = @Band.order(:
|
1438
|
+
bands = @Band.order(Sequel[:tracks][:name]).from(Sequel.expr(Sequel[:s][:bands]).as(Sequel.identifier(:tracks))).eager_graph(:tracks).all
|
1428
1439
|
bands.must_equal [@b1, @b2]
|
1429
1440
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1430
1441
|
|
1431
|
-
bands = @Band.order(:
|
1442
|
+
bands = @Band.order(Sequel[:tracks][:name]).from(Sequel.expr(Sequel[:s][:bands]).as('tracks')).eager_graph(:tracks).all
|
1432
1443
|
bands.must_equal [@b1, @b2]
|
1433
1444
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1434
1445
|
end
|
1435
1446
|
|
1436
1447
|
it "should have eager graphs work with join tables with aliases" do
|
1437
|
-
bands = @Band.order(:
|
1448
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel[:s][:albums].as(:tracks), :band_id=>Sequel.qualify(Sequel[:s][:bands], :id)).eager_graph(:albums=>:tracks).all
|
1438
1449
|
bands.must_equal [@b1, @b2]
|
1439
1450
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1440
1451
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1441
1452
|
|
1442
|
-
bands = @Band.order(:
|
1453
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel.as(Sequel[:s][:albums], :tracks), :band_id=>Sequel.qualify(Sequel[:s][:bands], :id)).eager_graph(:albums=>:tracks).all
|
1443
1454
|
bands.must_equal [@b1, @b2]
|
1444
1455
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1445
1456
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1446
1457
|
|
1447
|
-
bands = @Band.order(:
|
1458
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel.as(Sequel[:s][:albums], 'tracks'), :band_id=>Sequel.qualify(Sequel[:s][:bands], :id)).eager_graph(:albums=>:tracks).all
|
1448
1459
|
bands.must_equal [@b1, @b2]
|
1449
1460
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1450
1461
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1451
1462
|
|
1452
|
-
bands = @Band.order(:
|
1463
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel.as(Sequel[:s][:albums], Sequel.identifier(:tracks)), :band_id=>Sequel.qualify(Sequel[:s][:bands], :id)).eager_graph(:albums=>:tracks).all
|
1453
1464
|
bands.must_equal [@b1, @b2]
|
1454
1465
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1455
1466
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1456
1467
|
|
1457
|
-
bands = @Band.order(:
|
1468
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel[:s][:albums], {:band_id=>Sequel.qualify(Sequel[:s][:bands], :id)}, :table_alias=>:tracks).eager_graph(:albums=>:tracks).all
|
1458
1469
|
bands.must_equal [@b1, @b2]
|
1459
1470
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1460
1471
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1461
1472
|
|
1462
|
-
bands = @Band.order(:
|
1473
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel[:s][:albums], {:band_id=>Sequel.qualify(Sequel[:s][:bands], :id)}, :table_alias=>'tracks').eager_graph(:albums=>:tracks).all
|
1463
1474
|
bands.must_equal [@b1, @b2]
|
1464
1475
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1465
1476
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1466
1477
|
|
1467
|
-
bands = @Band.order(:
|
1478
|
+
bands = @Band.order(Sequel[:bands][:name]).eager_graph(:members).join(Sequel[:s][:albums], {:band_id=>Sequel.qualify(Sequel[:s][:bands], :id)}, :table_alias=>Sequel.identifier(:tracks)).eager_graph(:albums=>:tracks).all
|
1468
1479
|
bands.must_equal [@b1, @b2]
|
1469
1480
|
bands.map{|x| x.albums}.must_equal [[@a1, @a2], [@a3, @a4]]
|
1470
1481
|
bands.map{|x| x.members}.must_equal [[@m1, @m2], [@m4, @m3]]
|
1471
1482
|
end
|
1472
1483
|
|
1473
1484
|
it "should have eager graphs work with different types of qualified from tables" do
|
1474
|
-
bands = @Band.order(:
|
1485
|
+
bands = @Band.order(Sequel[:bands][:name]).from(Sequel.qualify(:s, :bands)).eager_graph(:tracks).all
|
1475
1486
|
bands.must_equal [@b1, @b2]
|
1476
1487
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1477
1488
|
|
1478
|
-
bands = @Band.order(:
|
1489
|
+
bands = @Band.order(Sequel[:bands][:name]).from(Sequel.identifier(:bands).qualify(:s)).eager_graph(:tracks).all
|
1479
1490
|
bands.must_equal [@b1, @b2]
|
1480
1491
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1481
1492
|
|
1482
|
-
bands = @Band.order(:
|
1493
|
+
bands = @Band.order(Sequel[:bands][:name]).from(Sequel::SQL::QualifiedIdentifier.new(:s, 'bands')).eager_graph(:tracks).all
|
1483
1494
|
bands.must_equal [@b1, @b2]
|
1484
1495
|
bands.map{|x| x.tracks}.must_equal [[@t1, @t2, @t3, @t4], []]
|
1485
1496
|
end
|
@@ -1610,7 +1621,7 @@ describe "Postgres::Database functions, languages, schemas, and triggers" do
|
|
1610
1621
|
@d.send(:drop_schema_sql, :sequel, :if_exists=>true, :cascade=>true).must_equal 'DROP SCHEMA IF EXISTS "sequel" CASCADE'
|
1611
1622
|
@d.create_schema(:sequel)
|
1612
1623
|
@d.create_schema(:sequel, :if_not_exists=>true) if @d.server_version >= 90300
|
1613
|
-
@d.create_table(:
|
1624
|
+
@d.create_table(Sequel[:sequel][:test]){Integer :a}
|
1614
1625
|
@d.drop_schema(:sequel, :if_exists=>true, :cascade=>true)
|
1615
1626
|
end
|
1616
1627
|
|
@@ -1634,8 +1645,8 @@ describe "Postgres::Database functions, languages, schemas, and triggers" do
|
|
1634
1645
|
@d.drop_trigger(:test, :identity, :if_exists=>true, :cascade=>true)
|
1635
1646
|
|
1636
1647
|
if @d.supports_trigger_conditions?
|
1637
|
-
@d.send(:create_trigger_sql, :test, :identity, :tf, :each_row=>true, :when=> {:
|
1638
|
-
@d.create_trigger(:test, :identity, :tf, :each_row=>true, :events => :update, :when=> {:
|
1648
|
+
@d.send(:create_trigger_sql, :test, :identity, :tf, :each_row=>true, :when=> {Sequel[:new][:name] => 'b'}).must_equal %q{CREATE TRIGGER identity BEFORE INSERT OR UPDATE OR DELETE ON "test" FOR EACH ROW WHEN ("new"."name" = 'b') EXECUTE PROCEDURE tf()}
|
1649
|
+
@d.create_trigger(:test, :identity, :tf, :each_row=>true, :events => :update, :when=> {Sequel[:new][:name] => 'b'})
|
1639
1650
|
@d[:test].filter(:name=>'a').update(:value=>nil)
|
1640
1651
|
@d[:test].filter(:name=>'a').all.must_equal [{:name=>'a', :value=>nil}]
|
1641
1652
|
proc{@d[:test].filter(:name=>'a').update(:name=>'b')}.must_raise(Sequel::DatabaseError)
|
@@ -1880,7 +1891,7 @@ if ((DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG) || DB.adapter_sc
|
|
1880
1891
|
end
|
1881
1892
|
|
1882
1893
|
it "should accept dataset as first argument" do
|
1883
|
-
@db.copy_table(@db[:test_copy].cross_join(:
|
1894
|
+
@db.copy_table(@db[:test_copy].cross_join(Sequel[:test_copy].as(:tc)).order(Sequel[:test_copy][:x], Sequel[:test_copy][:y], Sequel[:tc][:x], Sequel[:tc][:y])).must_equal "1\t2\t1\t2\n1\t2\t3\t4\n3\t4\t1\t2\n3\t4\t3\t4\n"
|
1884
1895
|
end
|
1885
1896
|
|
1886
1897
|
it "with a block and no options should yield each row as a string in text format" do
|
@@ -2625,11 +2636,11 @@ describe 'PostgreSQL hstore handling' do
|
|
2625
2636
|
|
2626
2637
|
c.many_to_one :item, :class=>c, :key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
|
2627
2638
|
c.one_to_many :items, :class=>c, :key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :key_method=>:item_id
|
2628
|
-
c.many_to_many :related_items, :class=>c, :join_table
|
2639
|
+
c.many_to_many :related_items, :class=>c, :join_table=>Sequel[:items].as(:i), :left_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer), :right_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
|
2629
2640
|
|
2630
2641
|
c.many_to_one :other_item, :class=>c, :key=>:id, :primary_key_method=>:item_id, :primary_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :reciprocal=>:other_items
|
2631
2642
|
c.one_to_many :other_items, :class=>c, :primary_key=>:item_id, :key=>:id, :primary_key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :reciprocal=>:other_item
|
2632
|
-
c.many_to_many :other_related_items, :class=>c, :join_table
|
2643
|
+
c.many_to_many :other_related_items, :class=>c, :join_table=>Sequel[:items].as(:i), :left_key=>:id, :right_key=>:id,
|
2633
2644
|
:left_primary_key_column=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer),
|
2634
2645
|
:left_primary_key=>:left_item_id,
|
2635
2646
|
:right_primary_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer),
|
@@ -2666,13 +2677,13 @@ describe 'PostgreSQL hstore handling' do
|
|
2666
2677
|
os.other_item.must_equal o
|
2667
2678
|
|
2668
2679
|
# Eager Loading via eager_graph
|
2669
|
-
c.eager_graph(:item).where(:
|
2670
|
-
c.eager_graph(:items).where(:
|
2671
|
-
c.eager_graph(:related_items).where(:
|
2672
|
-
c.eager_graph(:other_item).where(:
|
2673
|
-
c.eager_graph(:other_items).where(:
|
2674
|
-
c.eager_graph(:other_related_items).where(:
|
2675
|
-
c.eager_graph(:mtm_items).where(:
|
2680
|
+
c.eager_graph(:item).where(Sequel[:items][:id]=>1).all.first.item.must_equal o2
|
2681
|
+
c.eager_graph(:items).where(Sequel[:items][:id]=>2).all.first.items.must_equal [o]
|
2682
|
+
c.eager_graph(:related_items).where(Sequel[:items][:id]=>1).all.first.related_items.must_equal [o2]
|
2683
|
+
c.eager_graph(:other_item).where(Sequel[:items][:id]=>2).all.first.other_item.must_equal o
|
2684
|
+
c.eager_graph(:other_items).where(Sequel[:items][:id]=>1).all.first.other_items.must_equal [o2]
|
2685
|
+
c.eager_graph(:other_related_items).where(Sequel[:items][:id]=>1).all.first.other_related_items.must_equal [o]
|
2686
|
+
c.eager_graph(:mtm_items).where(Sequel[:items][:id]=>1).all.first.mtm_items.must_equal [o]
|
2676
2687
|
|
2677
2688
|
# Filter By Associations - Model Instances
|
2678
2689
|
c.filter(:item=>o2).all.must_equal [o]
|
@@ -2749,7 +2760,7 @@ describe 'PostgreSQL hstore handling' do
|
|
2749
2760
|
@ds.get(h2.akeys.length).must_equal 1
|
2750
2761
|
|
2751
2762
|
@ds.from(Sequel.hstore('t'=>'s').op.populate(Sequel::SQL::Cast.new(nil, :items))).select_map(:t).must_equal ['s']
|
2752
|
-
@ds.from(:
|
2763
|
+
@ds.from(Sequel[:items].as(:i)).select(Sequel.hstore('t'=>'s').op.record_set(:i).as(:r)).from_self(:alias=>:s).select(Sequel.lit('(r).*')).from_self.select_map(:t).must_equal ['s']
|
2753
2764
|
|
2754
2765
|
@ds.from(Sequel.hstore('t'=>'s', 'a'=>'b').op.skeys.as(:s)).select_order_map(:s).must_equal %w'a t'
|
2755
2766
|
@ds.from((Sequel.hstore('t'=>'s', 'a'=>'b').op - 'a').skeys.as(:s)).select_order_map(:s).must_equal %w't'
|
@@ -3444,7 +3455,7 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3444
3455
|
end
|
3445
3456
|
@db.register_row_type(:address)
|
3446
3457
|
@db.register_row_type(Sequel.qualify(:public, :person))
|
3447
|
-
@db.register_row_type(:
|
3458
|
+
@db.register_row_type(Sequel[:public][:company])
|
3448
3459
|
|
3449
3460
|
@native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
|
3450
3461
|
end
|
@@ -3487,8 +3498,8 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3487
3498
|
end
|
3488
3499
|
@db.register_row_type(:domain_check)
|
3489
3500
|
@db.get(@db.row_type(:domain_check, [1])).must_equal(:id=>1)
|
3490
|
-
@db.register_row_type(:
|
3491
|
-
@db.get(@db.row_type(:
|
3501
|
+
@db.register_row_type(Sequel[:public][:domain_check])
|
3502
|
+
@db.get(@db.row_type(Sequel[:public][:domain_check], [1])).must_equal(:id=>1)
|
3492
3503
|
@db.get(@db.row_type(Sequel.qualify(:public, :domain_check), [1])).must_equal(:id=>1)
|
3493
3504
|
ensure
|
3494
3505
|
@db.drop_table(:domain_check)
|
@@ -3572,7 +3583,7 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3572
3583
|
|
3573
3584
|
it "splat should reference the table type" do
|
3574
3585
|
@db[:b].select(:a).first.must_equal(:a=>1)
|
3575
|
-
@db[:b].select(:
|
3586
|
+
@db[:b].select(Sequel[:b][:a]).first.must_equal(:a=>1)
|
3576
3587
|
@db[:b].select(Sequel.pg_row(:b)[:a]).first.must_equal(:a=>2)
|
3577
3588
|
@db[:b].select(Sequel.pg_row(:b).splat[:a]).first.must_equal(:a=>1)
|
3578
3589
|
|
@@ -3589,11 +3600,11 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3589
3600
|
ds.first.must_equal(:b=>{:a=>1, :b=>{:a=>2}})
|
3590
3601
|
ds.select(Sequel.pg_row(:b).*).first.must_equal(:a=>1, :b=>{:a=>2})
|
3591
3602
|
ds.select(Sequel.pg_row(:b)[:b]).first.must_equal(:b=>{:a=>2})
|
3592
|
-
ds.select(Sequel.pg_row(:
|
3593
|
-
ds.select(Sequel.pg_row(:
|
3603
|
+
ds.select(Sequel.pg_row(Sequel[:t][:b]).*).first.must_equal(:a=>1, :b=>{:a=>2})
|
3604
|
+
ds.select(Sequel.pg_row(Sequel[:t][:b])[:b]).first.must_equal(:b=>{:a=>2})
|
3594
3605
|
end
|
3595
3606
|
ds.select(Sequel.pg_row(:b)[:a]).first.must_equal(:a=>1)
|
3596
|
-
ds.select(Sequel.pg_row(:
|
3607
|
+
ds.select(Sequel.pg_row(Sequel[:t][:b])[:a]).first.must_equal(:a=>1)
|
3597
3608
|
end
|
3598
3609
|
end
|
3599
3610
|
|