sequel 3.29.0 → 3.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/CHANGELOG +35 -3
  2. data/Rakefile +2 -1
  3. data/doc/association_basics.rdoc +11 -0
  4. data/doc/opening_databases.rdoc +2 -0
  5. data/doc/release_notes/3.30.0.txt +135 -0
  6. data/doc/testing.rdoc +17 -3
  7. data/lib/sequel/adapters/amalgalite.rb +2 -2
  8. data/lib/sequel/adapters/do/mysql.rb +5 -2
  9. data/lib/sequel/adapters/ibmdb.rb +2 -2
  10. data/lib/sequel/adapters/jdbc.rb +126 -43
  11. data/lib/sequel/adapters/jdbc/as400.rb +11 -3
  12. data/lib/sequel/adapters/jdbc/db2.rb +2 -1
  13. data/lib/sequel/adapters/jdbc/derby.rb +44 -19
  14. data/lib/sequel/adapters/jdbc/h2.rb +32 -19
  15. data/lib/sequel/adapters/jdbc/hsqldb.rb +21 -17
  16. data/lib/sequel/adapters/jdbc/jtds.rb +9 -4
  17. data/lib/sequel/adapters/jdbc/mssql.rb +3 -1
  18. data/lib/sequel/adapters/jdbc/mysql.rb +2 -1
  19. data/lib/sequel/adapters/jdbc/oracle.rb +21 -7
  20. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -2
  21. data/lib/sequel/adapters/jdbc/sqlite.rb +2 -1
  22. data/lib/sequel/adapters/jdbc/sqlserver.rb +48 -18
  23. data/lib/sequel/adapters/mock.rb +2 -1
  24. data/lib/sequel/adapters/mysql.rb +4 -2
  25. data/lib/sequel/adapters/mysql2.rb +2 -2
  26. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  27. data/lib/sequel/adapters/openbase.rb +1 -1
  28. data/lib/sequel/adapters/oracle.rb +6 -6
  29. data/lib/sequel/adapters/postgres.rb +25 -12
  30. data/lib/sequel/adapters/shared/access.rb +14 -6
  31. data/lib/sequel/adapters/shared/db2.rb +36 -13
  32. data/lib/sequel/adapters/shared/firebird.rb +12 -5
  33. data/lib/sequel/adapters/shared/informix.rb +11 -3
  34. data/lib/sequel/adapters/shared/mssql.rb +94 -47
  35. data/lib/sequel/adapters/shared/mysql.rb +107 -49
  36. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +2 -2
  37. data/lib/sequel/adapters/shared/oracle.rb +54 -27
  38. data/lib/sequel/adapters/shared/postgres.rb +65 -26
  39. data/lib/sequel/adapters/shared/progress.rb +4 -1
  40. data/lib/sequel/adapters/shared/sqlite.rb +36 -20
  41. data/lib/sequel/adapters/sqlite.rb +2 -3
  42. data/lib/sequel/adapters/swift/mysql.rb +3 -2
  43. data/lib/sequel/adapters/swift/sqlite.rb +2 -2
  44. data/lib/sequel/adapters/tinytds.rb +14 -8
  45. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +7 -4
  46. data/lib/sequel/database/misc.rb +6 -2
  47. data/lib/sequel/dataset/graph.rb +33 -7
  48. data/lib/sequel/dataset/prepared_statements.rb +19 -5
  49. data/lib/sequel/dataset/sql.rb +611 -201
  50. data/lib/sequel/model/associations.rb +12 -5
  51. data/lib/sequel/model/base.rb +20 -5
  52. data/lib/sequel/plugins/sharding.rb +9 -29
  53. data/lib/sequel/sql.rb +2 -1
  54. data/lib/sequel/timezones.rb +14 -4
  55. data/lib/sequel/version.rb +1 -1
  56. data/spec/adapters/mysql_spec.rb +10 -0
  57. data/spec/adapters/oracle_spec.rb +1 -1
  58. data/spec/core/core_sql_spec.rb +3 -1
  59. data/spec/core/database_spec.rb +42 -0
  60. data/spec/core/dataset_spec.rb +10 -3
  61. data/spec/core/mock_adapter_spec.rb +4 -0
  62. data/spec/core/object_graph_spec.rb +38 -0
  63. data/spec/extensions/association_autoreloading_spec.rb +1 -10
  64. data/spec/extensions/association_dependencies_spec.rb +2 -12
  65. data/spec/extensions/association_pks_spec.rb +35 -39
  66. data/spec/extensions/caching_spec.rb +23 -50
  67. data/spec/extensions/class_table_inheritance_spec.rb +30 -82
  68. data/spec/extensions/composition_spec.rb +18 -13
  69. data/spec/extensions/hook_class_methods_spec.rb +65 -91
  70. data/spec/extensions/identity_map_spec.rb +33 -103
  71. data/spec/extensions/instance_filters_spec.rb +10 -21
  72. data/spec/extensions/instance_hooks_spec.rb +6 -24
  73. data/spec/extensions/json_serializer_spec.rb +4 -5
  74. data/spec/extensions/lazy_attributes_spec.rb +16 -20
  75. data/spec/extensions/list_spec.rb +17 -39
  76. data/spec/extensions/many_through_many_spec.rb +135 -277
  77. data/spec/extensions/migration_spec.rb +18 -15
  78. data/spec/extensions/named_timezones_spec.rb +1 -1
  79. data/spec/extensions/nested_attributes_spec.rb +97 -92
  80. data/spec/extensions/optimistic_locking_spec.rb +9 -20
  81. data/spec/extensions/prepared_statements_associations_spec.rb +22 -37
  82. data/spec/extensions/prepared_statements_safe_spec.rb +9 -27
  83. data/spec/extensions/prepared_statements_spec.rb +11 -30
  84. data/spec/extensions/prepared_statements_with_pk_spec.rb +6 -13
  85. data/spec/extensions/pretty_table_spec.rb +1 -6
  86. data/spec/extensions/rcte_tree_spec.rb +41 -43
  87. data/spec/extensions/schema_dumper_spec.rb +3 -6
  88. data/spec/extensions/serialization_spec.rb +20 -32
  89. data/spec/extensions/sharding_spec.rb +66 -140
  90. data/spec/extensions/single_table_inheritance_spec.rb +14 -36
  91. data/spec/extensions/spec_helper.rb +10 -64
  92. data/spec/extensions/sql_expr_spec.rb +20 -60
  93. data/spec/extensions/tactical_eager_loading_spec.rb +9 -19
  94. data/spec/extensions/timestamps_spec.rb +6 -6
  95. data/spec/extensions/to_dot_spec.rb +1 -2
  96. data/spec/extensions/touch_spec.rb +13 -14
  97. data/spec/extensions/tree_spec.rb +11 -26
  98. data/spec/extensions/update_primary_key_spec.rb +30 -24
  99. data/spec/extensions/validation_class_methods_spec.rb +30 -51
  100. data/spec/extensions/validation_helpers_spec.rb +16 -35
  101. data/spec/integration/dataset_test.rb +16 -4
  102. data/spec/integration/prepared_statement_test.rb +4 -2
  103. data/spec/model/eager_loading_spec.rb +16 -0
  104. data/spec/model/model_spec.rb +15 -1
  105. data/spec/model/record_spec.rb +60 -0
  106. metadata +23 -40
@@ -740,6 +740,14 @@ describe Sequel::Model, "#eager_graph" do
740
740
  ds.all.should == [GraphAlbum.load(:id=>1, :band_id=>2, :band_id_0=>2, :vocalist_id=>3)]
741
741
  end
742
742
 
743
+ it "should not modify existing dataset" do
744
+ ds1 = GraphAlbum.dataset
745
+ ds2 = ds1.eager_graph(:band)
746
+ proc{ds1.eager_graph(:band)}.should_not raise_error
747
+ proc{ds2.eager_graph(:tracks)}.should_not raise_error
748
+ proc{ds2.eager_graph(:tracks)}.should_not raise_error
749
+ end
750
+
743
751
  it "should eagerly load a single many_to_one association" do
744
752
  ds = GraphAlbum.eager_graph(:band)
745
753
  ds.sql.should == 'SELECT albums.id, albums.band_id, band.id AS band_id_0, band.vocalist_id FROM albums LEFT OUTER JOIN bands AS band ON (band.id = albums.band_id)'
@@ -1081,6 +1089,14 @@ describe Sequel::Model, "#eager_graph" do
1081
1089
  GraphAlbum.eager_graph(:inner_genres).sql.should == 'SELECT albums.id, albums.band_id FROM albums LEFT OUTER JOIN ag ON (ag.album_id = albums.id) LEFT OUTER JOIN genres AS inner_genres ON (inner_genres.id = ag.genre_id)'
1082
1090
  end
1083
1091
 
1092
+ it "should respect the association's :graph_alias_base option" do
1093
+ GraphAlbum.many_to_one :inner_band, :class=>'GraphBand', :key=>:band_id, :graph_alias_base=>:foo
1094
+ ds = GraphAlbum.eager_graph(:inner_band)
1095
+ ds.sql.should == 'SELECT albums.id, albums.band_id, foo.id AS foo_id, foo.vocalist_id FROM albums LEFT OUTER JOIN bands AS foo ON (foo.id = albums.band_id)'
1096
+ GraphAlbum.one_to_many :right_tracks, :class=>'GraphTrack', :key=>:album_id, :graph_alias_base=>:foo
1097
+ ds.eager_graph(:right_tracks).sql.should == 'SELECT albums.id, albums.band_id, foo.id AS foo_id, foo.vocalist_id, foo_0.id AS foo_0_id, foo_0.album_id FROM albums LEFT OUTER JOIN bands AS foo ON (foo.id = albums.band_id) LEFT OUTER JOIN tracks AS foo_0 ON (foo_0.album_id = albums.id)'
1098
+ end
1099
+
1084
1100
  it "should respect the association's :graph_join_type option" do
1085
1101
  GraphAlbum.many_to_one :inner_band, :class=>'GraphBand', :key=>:band_id, :graph_join_type=>:inner
1086
1102
  GraphAlbum.eager_graph(:inner_band).sql.should == 'SELECT albums.id, albums.band_id, inner_band.id AS inner_band_id, inner_band.vocalist_id FROM albums INNER JOIN bands AS inner_band ON (inner_band.id = albums.band_id)'
@@ -214,11 +214,25 @@ describe Sequel::Model, "dataset & schema" do
214
214
  proc{@model.set_dataset(Object.new)}.should raise_error(Sequel::Error)
215
215
  end
216
216
 
217
- it "set_dataset should add the destroy method to the dataset" do
217
+ it "set_dataset should add the destroy method to the dataset that destroys each object" do
218
218
  ds = MODEL_DB[:foo]
219
219
  ds.should_not respond_to(:destroy)
220
220
  @model.set_dataset(ds)
221
221
  ds.should respond_to(:destroy)
222
+ MODEL_DB.sqls
223
+ ds._fetch = [{:id=>1}, {:id=>2}]
224
+ ds.destroy.should == 2
225
+ MODEL_DB.sqls.should == ["SELECT * FROM foo", "DELETE FROM foo WHERE (id = 1)", "DELETE FROM foo WHERE (id = 2)"]
226
+ end
227
+
228
+ it "set_dataset should add the destroy method that respects sharding with transactions" do
229
+ db = Sequel.mock(:servers=>{:s1=>{}})
230
+ ds = db[:foo].server(:s1)
231
+ @model.use_transactions = true
232
+ @model.set_dataset(ds)
233
+ db.sqls
234
+ ds.destroy.should == 0
235
+ db.sqls.should == ["BEGIN -- s1", "SELECT * FROM foo -- s1", "COMMIT -- s1"]
222
236
  end
223
237
 
224
238
  it "should raise an error on set_dataset if there is an error connecting to the database" do
@@ -270,6 +270,66 @@ describe "Model#save" do
270
270
  proc { o.save(:y) }.should raise_error(Sequel::Rollback)
271
271
  MODEL_DB.sqls.should == []
272
272
  end
273
+
274
+ it "should support a :server option to set the server/shard to use" do
275
+ db = Sequel.mock(:fetch=>{:id=>13, :x=>1}, :autoid=>proc{13}, :numrows=>1, :servers=>{:s1=>{}})
276
+ c = Class.new(Sequel::Model(db[:items]))
277
+ c.columns :id, :x
278
+ db.sqls
279
+ o = c.new(:x => 1)
280
+ o.save(:server=>:s1)
281
+ db.sqls.should == ["INSERT INTO items (x) VALUES (1) -- s1", "SELECT * FROM items WHERE (id = 13) LIMIT 1 -- s1"]
282
+ o.save(:server=>:s1, :transaction=>true)
283
+ db.sqls.should == ["BEGIN -- s1", "UPDATE items SET x = 1 WHERE (id = 13) -- s1", 'COMMIT -- s1']
284
+ end
285
+ end
286
+
287
+ describe "Model#set_server" do
288
+ before do
289
+ @db = Sequel.mock(:fetch=>{:id=>13, :x=>1}, :autoid=>proc{13}, :numrows=>1, :servers=>{:s1=>{}})
290
+ @c = Class.new(Sequel::Model(@db[:items])) do
291
+ columns :id, :x
292
+ end
293
+ @db.sqls
294
+ end
295
+
296
+ it "should set the server to use when inserting" do
297
+ @c.new(:x => 1).set_server(:s1).save
298
+ @db.sqls.should == ["INSERT INTO items (x) VALUES (1) -- s1", "SELECT * FROM items WHERE (id = 13) LIMIT 1 -- s1"]
299
+ end
300
+
301
+ it "should set the server to use when updating" do
302
+ @c.load(:id=>13, :x => 1).set_server(:s1).save
303
+ @db.sqls.should == ["UPDATE items SET x = 1 WHERE (id = 13) -- s1"]
304
+ end
305
+
306
+ it "should set the server to use for transactions when saving" do
307
+ @c.load(:id=>13, :x => 1).set_server(:s1).save(:transaction=>true)
308
+ @db.sqls.should == ["BEGIN -- s1", "UPDATE items SET x = 1 WHERE (id = 13) -- s1", 'COMMIT -- s1']
309
+ end
310
+
311
+ it "should set the server to use when deleting" do
312
+ @c.load(:id=>13).set_server(:s1).delete
313
+ @db.sqls.should == ["DELETE FROM items WHERE (id = 13) -- s1"]
314
+ end
315
+
316
+ it "should set the server to use for transactions when destroying" do
317
+ o = @c.load(:id=>13).set_server(:s1)
318
+ o.use_transactions = true
319
+ o.destroy
320
+ @db.sqls.should == ["BEGIN -- s1", "DELETE FROM items WHERE (id = 13) -- s1", 'COMMIT -- s1']
321
+ end
322
+
323
+ it "should set the server on this if this is already loaded" do
324
+ o = @c.load(:id=>13, :x => 1)
325
+ o.this
326
+ o.set_server(:s1)
327
+ o.this.opts[:server].should == :s1
328
+ end
329
+
330
+ it "should set the server on this if this is not already loaded" do
331
+ @c.load(:id=>13, :x => 1).set_server(:s1).this.opts[:server].should == :s1
332
+ end
273
333
  end
274
334
 
275
335
  describe "Model#marshallable" do
metadata CHANGED
@@ -1,30 +1,22 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
- version: !ruby/object:Gem::Version
4
- hash: 115
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.30.0
5
5
  prerelease:
6
- segments:
7
- - 3
8
- - 29
9
- - 0
10
- version: 3.29.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jeremy Evans
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-01 00:00:00 Z
12
+ date: 2011-12-01 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: The Database Toolkit for Ruby
22
15
  email: code@jeremyevans.net
23
- executables:
16
+ executables:
24
17
  - sequel
25
18
  extensions: []
26
-
27
- extra_rdoc_files:
19
+ extra_rdoc_files:
28
20
  - README.rdoc
29
21
  - CHANGELOG
30
22
  - MIT-LICENSE
@@ -96,7 +88,8 @@ extra_rdoc_files:
96
88
  - doc/release_notes/3.27.0.txt
97
89
  - doc/release_notes/3.28.0.txt
98
90
  - doc/release_notes/3.29.0.txt
99
- files:
91
+ - doc/release_notes/3.30.0.txt
92
+ files:
100
93
  - MIT-LICENSE
101
94
  - CHANGELOG
102
95
  - README.rdoc
@@ -162,6 +155,7 @@ files:
162
155
  - doc/release_notes/3.27.0.txt
163
156
  - doc/release_notes/3.28.0.txt
164
157
  - doc/release_notes/3.29.0.txt
158
+ - doc/release_notes/3.30.0.txt
165
159
  - doc/sharding.rdoc
166
160
  - doc/sql.rdoc
167
161
  - doc/validations.rdoc
@@ -475,44 +469,33 @@ files:
475
469
  - lib/sequel_model.rb
476
470
  homepage: http://sequel.rubyforge.org
477
471
  licenses: []
478
-
479
472
  post_install_message:
480
- rdoc_options:
473
+ rdoc_options:
481
474
  - --quiet
482
475
  - --line-numbers
483
476
  - --inline-source
484
477
  - --title
485
- - "Sequel: The Database Toolkit for Ruby"
478
+ - ! 'Sequel: The Database Toolkit for Ruby'
486
479
  - --main
487
480
  - README.rdoc
488
- require_paths:
481
+ require_paths:
489
482
  - lib
490
- required_ruby_version: !ruby/object:Gem::Requirement
483
+ required_ruby_version: !ruby/object:Gem::Requirement
491
484
  none: false
492
- requirements:
493
- - - ">="
494
- - !ruby/object:Gem::Version
495
- hash: 63
496
- segments:
497
- - 1
498
- - 8
499
- - 4
485
+ requirements:
486
+ - - ! '>='
487
+ - !ruby/object:Gem::Version
500
488
  version: 1.8.4
501
- required_rubygems_version: !ruby/object:Gem::Requirement
489
+ required_rubygems_version: !ruby/object:Gem::Requirement
502
490
  none: false
503
- requirements:
504
- - - ">="
505
- - !ruby/object:Gem::Version
506
- hash: 3
507
- segments:
508
- - 0
509
- version: "0"
491
+ requirements:
492
+ - - ! '>='
493
+ - !ruby/object:Gem::Version
494
+ version: '0'
510
495
  requirements: []
511
-
512
496
  rubyforge_project: sequel
513
- rubygems_version: 1.8.10
497
+ rubygems_version: 1.8.11
514
498
  signing_key:
515
499
  specification_version: 3
516
500
  summary: The Database Toolkit for Ruby
517
501
  test_files: []
518
-