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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +34 -0
  3. data/README.rdoc +8 -4
  4. data/doc/active_record.rdoc +1 -1
  5. data/doc/advanced_associations.rdoc +7 -7
  6. data/doc/association_basics.rdoc +7 -7
  7. data/doc/cheat_sheet.rdoc +5 -3
  8. data/doc/core_extensions.rdoc +3 -3
  9. data/doc/dataset_filtering.rdoc +1 -1
  10. data/doc/object_model.rdoc +16 -7
  11. data/doc/postgresql.rdoc +3 -3
  12. data/doc/querying.rdoc +3 -3
  13. data/doc/release_notes/4.40.0.txt +179 -0
  14. data/doc/security.rdoc +2 -1
  15. data/doc/sql.rdoc +34 -18
  16. data/doc/testing.rdoc +1 -0
  17. data/doc/virtual_rows.rdoc +11 -2
  18. data/lib/sequel/adapters/jdbc/derby.rb +7 -1
  19. data/lib/sequel/adapters/jdbc/h2.rb +15 -1
  20. data/lib/sequel/adapters/oracle.rb +9 -5
  21. data/lib/sequel/adapters/postgres.rb +0 -1
  22. data/lib/sequel/adapters/shared/cubrid.rb +11 -11
  23. data/lib/sequel/adapters/shared/db2.rb +4 -8
  24. data/lib/sequel/adapters/shared/mssql.rb +41 -28
  25. data/lib/sequel/adapters/shared/mysql.rb +9 -6
  26. data/lib/sequel/adapters/shared/oracle.rb +16 -5
  27. data/lib/sequel/adapters/shared/postgres.rb +84 -45
  28. data/lib/sequel/adapters/shared/sqlanywhere.rb +29 -15
  29. data/lib/sequel/adapters/shared/sqlite.rb +6 -6
  30. data/lib/sequel/core.rb +61 -10
  31. data/lib/sequel/database/connecting.rb +2 -1
  32. data/lib/sequel/database/features.rb +7 -0
  33. data/lib/sequel/database/query.rb +1 -1
  34. data/lib/sequel/database/schema_methods.rb +30 -3
  35. data/lib/sequel/database/transactions.rb +4 -2
  36. data/lib/sequel/dataset/actions.rb +1 -1
  37. data/lib/sequel/dataset/graph.rb +6 -1
  38. data/lib/sequel/dataset/query.rb +14 -7
  39. data/lib/sequel/dataset/sql.rb +2 -2
  40. data/lib/sequel/extensions/core_extensions.rb +2 -1
  41. data/lib/sequel/extensions/pg_row.rb +2 -2
  42. data/lib/sequel/extensions/s.rb +57 -0
  43. data/lib/sequel/extensions/set_overrides.rb +5 -1
  44. data/lib/sequel/extensions/sql_expr.rb +1 -0
  45. data/lib/sequel/extensions/symbol_aref.rb +71 -0
  46. data/lib/sequel/extensions/symbol_aref_refinement.rb +41 -0
  47. data/lib/sequel/extensions/symbol_as.rb +23 -0
  48. data/lib/sequel/extensions/symbol_as_refinement.rb +35 -0
  49. data/lib/sequel/model/base.rb +3 -3
  50. data/lib/sequel/plugins/class_table_inheritance.rb +14 -3
  51. data/lib/sequel/plugins/column_select.rb +4 -2
  52. data/lib/sequel/plugins/dataset_associations.rb +12 -4
  53. data/lib/sequel/plugins/insert_returning_select.rb +1 -1
  54. data/lib/sequel/plugins/mssql_optimistic_locking.rb +1 -1
  55. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  56. data/lib/sequel/sql.rb +40 -8
  57. data/lib/sequel/version.rb +1 -1
  58. data/spec/adapters/firebird_spec.rb +3 -3
  59. data/spec/adapters/mssql_spec.rb +40 -40
  60. data/spec/adapters/mysql_spec.rb +5 -5
  61. data/spec/adapters/oracle_spec.rb +4 -4
  62. data/spec/adapters/postgres_spec.rb +135 -124
  63. data/spec/adapters/spec_helper.rb +1 -0
  64. data/spec/adapters/sqlite_spec.rb +6 -6
  65. data/spec/core/dataset_spec.rb +2 -2
  66. data/spec/core/expression_filters_spec.rb +43 -2
  67. data/spec/core/schema_spec.rb +35 -1
  68. data/spec/core_extensions_spec.rb +27 -0
  69. data/spec/extensions/class_table_inheritance_spec.rb +8 -0
  70. data/spec/extensions/column_select_spec.rb +8 -0
  71. data/spec/extensions/core_refinements_spec.rb +1 -1
  72. data/spec/extensions/dataset_associations_spec.rb +9 -0
  73. data/spec/extensions/insert_returning_select_spec.rb +20 -0
  74. data/spec/extensions/prepared_statements_spec.rb +7 -0
  75. data/spec/extensions/s_spec.rb +60 -0
  76. data/spec/extensions/symbol_aref_refinement_spec.rb +28 -0
  77. data/spec/extensions/symbol_as_refinement_spec.rb +21 -0
  78. data/spec/integration/associations_test.rb +62 -57
  79. data/spec/integration/dataset_test.rb +54 -54
  80. data/spec/integration/eager_loader_test.rb +7 -7
  81. data/spec/integration/plugin_test.rb +20 -20
  82. data/spec/integration/prepared_statement_test.rb +1 -1
  83. data/spec/integration/schema_test.rb +21 -0
  84. data/spec/integration/spec_helper.rb +1 -0
  85. metadata +12 -2
@@ -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, :items__value)).sql.must_equal 'SELECT max(`items`.`value`) FROM `items`'
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, :abc__def, 'hello')).sql.must_equal "SELECT test(`abc`.`def`, 'hello') FROM `items`"
187
- @d.select(Sequel.function(:test, :abc__def, 'hello').as(:x2)).sql.must_equal "SELECT test(`abc`.`def`, 'hello') AS `x2` FROM `items`"
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(:a__id=>1).delete
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(:a__id=>1).delete
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(:books__id, :title, :cat_name).order(:books__id).to_a.must_equal [
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(:books__id, :title, :cat_name).order(:books__id).limit(2, 1).to_a.must_equal [
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(:books__id, :title, :cat_name).order(:books__id).to_a.must_equal [
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(:books__id, :title, :cat_name).reverse_order(:books__id).limit(2, 0).to_a.must_equal [
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(:public__tmp_dolls).must_equal 0
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(:public__tmp_dolls).must_equal 1
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=>{:ic_test__b=>4}).insert(1, 3, 4).must_equal nil
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=>{:ic_test__b=>4}).insert(1, 3, 4).must_equal nil
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!(:public__testfk){primary_key :id; foreign_key :i, :public__testfk}
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?(:public__testfk)
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[:public__testfk].insert}}}.must_raise(Sequel::DatabaseError)
272
- proc{@db.transaction(:auto_savepoint=>true, :read_only=>true){@db.transaction(:read_only=>false){@db[:public__testfk].insert}}}.must_raise(Sequel::DatabaseError)
273
- @db[:public__testfk].delete
274
- @db.transaction{@db[:public__testfk].insert; @db.transaction(:savepoint=>true, :read_only=>true){@db[:public__testfk].all;}}
275
- @db.transaction{@db.transaction(:savepoint=>true, :read_only=>true){}; @db[:public__testfk].insert}
276
- @db.transaction{@db[:public__testfk].all; @db.transaction(:savepoint=>true, :read_only=>true){@db[:public__testfk].all;}}
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[:public__testfk].disable_insert_returning
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[:public__testfk]
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{pg_catalog__sum.function(1)}.must_equal 1
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(:public, :testfk))
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(:public, :testfkv))
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(:public__testfk, :reload=>true).map{|c,s| [c, s[:oid]]}.must_equal [[:id, 23], [:i, 23]]
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(: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}]
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, :items__value)).sql.must_equal 'SELECT max("items"."value") FROM "test"'
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, :abc__def, 'hello')).sql.must_equal "SELECT test(\"abc\".\"def\", 'hello') FROM \"test\""
417
- @d.select(Sequel.function(:test, :abc__def, 'hello').as(:x2)).sql.must_equal "SELECT test(\"abc\".\"def\", 'hello') AS \"x2\" FROM \"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(:value___v, :xid___x).insert_select(:value=>10)
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(:value___v, :xid___x).prepare(:insert_select, :insert_select, :value=>10).call
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(:schema_test__schema_test){primary_key :i}
1197
- @db[:schema_test__schema_test].first.must_equal nil
1198
- @db[:schema_test__schema_test].insert(:i=>1).must_equal 1
1199
- @db[:schema_test__schema_test].first.must_equal(:i=>1)
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(:schema_test__schema_test)
1212
+ @db.drop_table(Sequel[:schema_test][:schema_test])
1202
1213
  @db.create_table(Sequel.qualify(:schema_test, :schema_test)){integer :i}
1203
- @db[:schema_test__schema_test].first.must_equal nil
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(:schema_test__schema_test){integer :i}
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(:schema_test__schema_test){integer :i}
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(:schema_test__domains){integer :i}
1222
- sch = @db.schema(:schema_test__domains)
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(:schema_test__domains){integer :i}
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!(:public__domains){integer :d}
1240
- @db.create_table(:schema_test__domains){integer :i}
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(:schema_test__domains).map{|x| x.first}.must_equal [:i]
1254
+ @db.schema(Sequel[:schema_test][:domains]).map{|x| x.first}.must_equal [:i]
1244
1255
  ensure
1245
- @db.drop_table?(:public__domains)
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(:schema_test__schema_test){integer :i}
1251
- @db.table_exists?(:schema_test__schema_test).must_equal true
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(:schema_test__schema_test){Integer :i, :index=>true}
1256
- @db.indexes(:schema_test__schema_test).keys.must_equal [:schema_test_schema_test_i_index]
1257
- @db.drop_index :schema_test__schema_test, :i
1258
- @db.indexes(:schema_test__schema_test).keys.must_equal []
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(:schema_test__schema_test){primary_key :i}
1263
- @db.primary_key(:schema_test__schema_test).must_equal 'i'
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(:schema_test__schema_test){primary_key :i}
1268
- @db.primary_key_sequence(:schema_test__schema_test).must_equal '"schema_test"."schema_test_i_seq"'
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(:"schema_test__schema test"){primary_key :i}
1273
- @db.primary_key_sequence(:"schema_test__schema test").must_equal '"schema_test"."schema test_i_seq"'
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(:schema_test__schema_test){integer :j; primary_key :k, :type=>:integer, :default=>Sequel.lit("nextval('schema_test.kseq'::regclass)")}
1279
- @db.primary_key_sequence(:schema_test__schema_test).must_equal '"schema_test".kseq'
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(:"schema_test__schema test"){integer :j; primary_key :k, :type=>:integer, :default=>Sequel.lit("nextval('schema_test.\"ks eq\"'::regclass)")}
1285
- @db.primary_key_sequence(:"schema_test__schema test").must_equal '"schema_test"."ks eq"'
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(:schema_test__schema_test) do
1301
+ @db.create_table(Sequel[:schema_test][:schema_test]) do
1291
1302
  primary_key :id
1292
- foreign_key :i, :schema_test__schema_test, :index=>{:name=>:schema_test_sti}
1303
+ foreign_key :i, Sequel[:schema_test][:schema_test], :index=>{:name=>:schema_test_sti}
1293
1304
  end
1294
- @db.create_table!(:public__schema_test) do
1305
+ @db.create_table!(Sequel[:public][:schema_test]) do
1295
1306
  primary_key :id
1296
- foreign_key :j, :public__schema_test, :index=>{:name=>:public_test_sti}
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?(:public__schema_test)
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(:s__bands){primary_key :id; String :name}
1318
- @db.create_table(:s__albums){primary_key :id; String :name; foreign_key :band_id, :s__bands}
1319
- @db.create_table(:s__tracks){primary_key :id; String :name; foreign_key :album_id, :s__albums}
1320
- @db.create_table(:s__members){primary_key :id; String :name; foreign_key :band_id, :s__bands}
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(:s__bands))
1323
- @Album = Class.new(Sequel::Model(:s__albums))
1324
- @Track = Class.new(Sequel::Model(:s__tracks))
1325
- @Member = Class.new(Sequel::Model(:s__members))
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=>:s__bands, :right_key=>:id, :left_key=>:id, :left_primary_key=>:band_id, :right_primary_key=>:band_id, :order=>:name
1339
- @Band.many_to_many :tracks, :class=>@Track, :join_table=>:s__albums, :right_key=>:id, :right_primary_key=>:album_id, :order=>:name
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(:bands__name).eager_graph(:albums).all
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(:bands__name).eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph({:albums=>:tracks}, :members).all
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(:bands__name).select_all(:s__bands).join(:s__members, :band_id=>:id).from_self(:alias=>:bands0).eager_graph(:albums=>:tracks).all
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(:bands__name).select_all(:s__bands).join(:s__members, :band_id=>:id).eager_graph({:albums=>:tracks}, :members).all
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(:bands__name).eager_graph(:tracks=>{:album=>:band}).all
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(:members__name).eager_graph(:members).all
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(:members__name).eager_graph(:band, :members=>:band).all
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(:bands__name).from_self.eager_graph(:tracks=>{:album=>:band}).all
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(:tracks__name).from(:s__bands___tracks).eager_graph(:tracks).all
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(:tracks__name).from(Sequel.expr(:s__bands).as(:tracks)).eager_graph(:tracks).all
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(:tracks__name).from(Sequel.expr(:s__bands).as(Sequel.identifier(:tracks))).eager_graph(:tracks).all
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(:tracks__name).from(Sequel.expr(:s__bands).as('tracks')).eager_graph(:tracks).all
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(:bands__name).eager_graph(:members).join(:s__albums___tracks, :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph(:members).join(Sequel.as(:s__albums, :tracks), :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph(:members).join(Sequel.as(:s__albums, 'tracks'), :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph(:members).join(Sequel.as(:s__albums, Sequel.identifier(:tracks)), :band_id=>Sequel.qualify(:s__bands, :id)).eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>Sequel.qualify(:s__bands, :id)}, :table_alias=>:tracks).eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>Sequel.qualify(:s__bands, :id)}, :table_alias=>'tracks').eager_graph(:albums=>:tracks).all
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(:bands__name).eager_graph(:members).join(:s__albums, {:band_id=>Sequel.qualify(:s__bands, :id)}, :table_alias=>Sequel.identifier(:tracks)).eager_graph(:albums=>:tracks).all
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(:bands__name).from(Sequel.qualify(:s, :bands)).eager_graph(:tracks).all
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(:bands__name).from(Sequel.identifier(:bands).qualify(:s)).eager_graph(:tracks).all
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(:bands__name).from(Sequel::SQL::QualifiedIdentifier.new(:s, 'bands')).eager_graph(:tracks).all
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(:sequel__test){Integer :a}
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=> {: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()}
1638
- @d.create_trigger(:test, :identity, :tf, :each_row=>true, :events => :update, :when=> {:new__name => 'b'})
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(:test_copy___tc).order(:test_copy__x, :test_copy__y, :tc__x, :tc__y)).must_equal "1\t2\t1\t2\n1\t2\t3\t4\n3\t4\t1\t2\n3\t4\t3\t4\n"
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=>:items___i, :left_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer), :right_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
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=>:items___i, :left_key=>:id, :right_key=>:id,
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(:items__id=>1).all.first.item.must_equal o2
2670
- c.eager_graph(:items).where(:items__id=>2).all.first.items.must_equal [o]
2671
- c.eager_graph(:related_items).where(:items__id=>1).all.first.related_items.must_equal [o2]
2672
- c.eager_graph(:other_item).where(:items__id=>2).all.first.other_item.must_equal o
2673
- c.eager_graph(:other_items).where(:items__id=>1).all.first.other_items.must_equal [o2]
2674
- c.eager_graph(:other_related_items).where(:items__id=>1).all.first.other_related_items.must_equal [o]
2675
- c.eager_graph(:mtm_items).where(:items__id=>1).all.first.mtm_items.must_equal [o]
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(:items___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']
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(:public__company)
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(:public__domain_check)
3491
- @db.get(@db.row_type(:public__domain_check, [1])).must_equal(:id=>1)
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(:b__a).first.must_equal(:a=>1)
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(:t__b).*).first.must_equal(:a=>1, :b=>{:a=>2})
3593
- ds.select(Sequel.pg_row(:t__b)[:b]).first.must_equal(:b=>{:a=>2})
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(:t__b)[:a]).first.must_equal(:a=>1)
3607
+ ds.select(Sequel.pg_row(Sequel[:t][:b])[:a]).first.must_equal(:a=>1)
3597
3608
  end
3598
3609
  end
3599
3610