sequel 3.43.0 → 3.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +32 -0
  2. data/doc/association_basics.rdoc +10 -3
  3. data/doc/release_notes/3.37.0.txt +1 -1
  4. data/doc/release_notes/3.44.0.txt +152 -0
  5. data/lib/sequel/adapters/ado.rb +0 -6
  6. data/lib/sequel/adapters/db2.rb +0 -3
  7. data/lib/sequel/adapters/dbi.rb +0 -6
  8. data/lib/sequel/adapters/ibmdb.rb +0 -3
  9. data/lib/sequel/adapters/jdbc.rb +8 -12
  10. data/lib/sequel/adapters/jdbc/as400.rb +2 -18
  11. data/lib/sequel/adapters/jdbc/derby.rb +10 -0
  12. data/lib/sequel/adapters/jdbc/h2.rb +10 -0
  13. data/lib/sequel/adapters/jdbc/hsqldb.rb +10 -0
  14. data/lib/sequel/adapters/jdbc/sqlite.rb +5 -0
  15. data/lib/sequel/adapters/jdbc/sqlserver.rb +2 -4
  16. data/lib/sequel/adapters/mock.rb +5 -0
  17. data/lib/sequel/adapters/mysql2.rb +4 -13
  18. data/lib/sequel/adapters/odbc.rb +0 -5
  19. data/lib/sequel/adapters/oracle.rb +3 -5
  20. data/lib/sequel/adapters/postgres.rb +2 -1
  21. data/lib/sequel/adapters/shared/access.rb +10 -0
  22. data/lib/sequel/adapters/shared/cubrid.rb +9 -0
  23. data/lib/sequel/adapters/shared/db2.rb +10 -0
  24. data/lib/sequel/adapters/shared/mssql.rb +10 -0
  25. data/lib/sequel/adapters/shared/mysql.rb +14 -0
  26. data/lib/sequel/adapters/shared/oracle.rb +15 -0
  27. data/lib/sequel/adapters/shared/postgres.rb +26 -2
  28. data/lib/sequel/adapters/shared/sqlite.rb +15 -0
  29. data/lib/sequel/adapters/tinytds.rb +5 -32
  30. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +2 -37
  31. data/lib/sequel/core.rb +3 -3
  32. data/lib/sequel/database/misc.rb +40 -4
  33. data/lib/sequel/database/query.rb +1 -1
  34. data/lib/sequel/database/schema_methods.rb +33 -12
  35. data/lib/sequel/dataset/actions.rb +51 -2
  36. data/lib/sequel/dataset/features.rb +0 -6
  37. data/lib/sequel/dataset/sql.rb +1 -1
  38. data/lib/sequel/exceptions.rb +22 -7
  39. data/lib/sequel/extensions/columns_introspection.rb +30 -5
  40. data/lib/sequel/extensions/pg_auto_parameterize.rb +9 -0
  41. data/lib/sequel/model/associations.rb +50 -37
  42. data/lib/sequel/model/base.rb +30 -1
  43. data/lib/sequel/plugins/eager_each.rb +17 -21
  44. data/lib/sequel/plugins/identity_map.rb +2 -1
  45. data/lib/sequel/plugins/many_through_many.rb +1 -1
  46. data/lib/sequel/plugins/single_table_inheritance.rb +2 -2
  47. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  48. data/lib/sequel/sql.rb +4 -2
  49. data/lib/sequel/version.rb +1 -1
  50. data/spec/adapters/postgres_spec.rb +32 -2
  51. data/spec/adapters/sqlite_spec.rb +20 -0
  52. data/spec/core/database_spec.rb +40 -0
  53. data/spec/core/dataset_spec.rb +91 -4
  54. data/spec/core/mock_adapter_spec.rb +2 -1
  55. data/spec/core/schema_generator_spec.rb +4 -0
  56. data/spec/core/schema_spec.rb +9 -3
  57. data/spec/extensions/association_dependencies_spec.rb +3 -3
  58. data/spec/extensions/columns_introspection_spec.rb +28 -2
  59. data/spec/extensions/eager_each_spec.rb +0 -1
  60. data/spec/extensions/identity_map_spec.rb +3 -2
  61. data/spec/extensions/migration_spec.rb +6 -0
  62. data/spec/extensions/prepared_statements_associations_spec.rb +2 -2
  63. data/spec/extensions/rcte_tree_spec.rb +2 -2
  64. data/spec/extensions/single_table_inheritance_spec.rb +3 -0
  65. data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
  66. data/spec/extensions/validation_class_methods_spec.rb +8 -0
  67. data/spec/integration/associations_test.rb +4 -4
  68. data/spec/integration/database_test.rb +68 -20
  69. data/spec/integration/dataset_test.rb +48 -0
  70. data/spec/integration/schema_test.rb +25 -1
  71. data/spec/model/associations_spec.rb +21 -8
  72. data/spec/model/dataset_methods_spec.rb +58 -18
  73. metadata +4 -2
@@ -250,11 +250,11 @@ describe Sequel::Model, "many_to_one" do
250
250
  it "should use :conditions option if given" do
251
251
  @c2.many_to_one :parent, :class => @c2, :key => :blah, :conditions=>{:a=>32}
252
252
  @c2.new(:id => 1, :blah => 567).parent
253
- MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE ((nodes.id = 567) AND (a = 32)) LIMIT 1"]
253
+ MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE ((a = 32) AND (nodes.id = 567)) LIMIT 1"]
254
254
 
255
255
  @c2.many_to_one :parent, :class => @c2, :key => :blah, :conditions=>:a
256
256
  @c2.new(:id => 1, :blah => 567).parent
257
- MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE ((nodes.id = 567) AND a) LIMIT 1"]
257
+ MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE (a AND (nodes.id = 567)) LIMIT 1"]
258
258
  end
259
259
 
260
260
  it "should support :order, :limit (only for offset), and :dataset options, as well as a block" do
@@ -711,7 +711,7 @@ describe Sequel::Model, "one_to_one" do
711
711
  end
712
712
  attrib = @c1.load(:id=>3)
713
713
  @c2.new(:id => 1234).attribute = attrib
714
- MODEL_DB.sqls.should == ['UPDATE attributes SET node_id = NULL WHERE ((node_id = 1234) AND (a = 1) AND (b = 2) AND (id != 3))',
714
+ MODEL_DB.sqls.should == ['UPDATE attributes SET node_id = NULL WHERE ((a = 1) AND (node_id = 1234) AND (b = 2) AND (id != 3))',
715
715
  "UPDATE attributes SET node_id = 1234 WHERE (id = 3)"]
716
716
  end
717
717
 
@@ -824,11 +824,11 @@ describe Sequel::Model, "one_to_one" do
824
824
  it "should use :conditions option if given" do
825
825
  @c2.one_to_one :parent, :class => @c2, :conditions=>{:a=>32}
826
826
  @c2.new(:id => 567).parent
827
- MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE ((nodes.node_id = 567) AND (a = 32)) LIMIT 1"]
827
+ MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE ((a = 32) AND (nodes.node_id = 567)) LIMIT 1"]
828
828
 
829
829
  @c2.one_to_one :parent, :class => @c2, :conditions=>:a
830
830
  @c2.new(:id => 567).parent
831
- MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE ((nodes.node_id = 567) AND a) LIMIT 1"]
831
+ MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE (a AND (nodes.node_id = 567)) LIMIT 1"]
832
832
  end
833
833
 
834
834
  it "should support :order, :limit (only for offset), and :dataset options, as well as a block" do
@@ -1364,9 +1364,9 @@ describe Sequel::Model, "one_to_many" do
1364
1364
 
1365
1365
  it "should support a conditions option" do
1366
1366
  @c2.one_to_many :attributes, :class => @c1, :conditions => {:a=>32}
1367
- @c2.new(:id => 1234).attributes_dataset.sql.should == "SELECT * FROM attributes WHERE ((attributes.node_id = 1234) AND (a = 32))"
1367
+ @c2.new(:id => 1234).attributes_dataset.sql.should == "SELECT * FROM attributes WHERE ((a = 32) AND (attributes.node_id = 1234))"
1368
1368
  @c2.one_to_many :attributes, :class => @c1, :conditions => Sequel.~(:a)
1369
- @c2.new(:id => 1234).attributes_dataset.sql.should == "SELECT * FROM attributes WHERE ((attributes.node_id = 1234) AND NOT a)"
1369
+ @c2.new(:id => 1234).attributes_dataset.sql.should == "SELECT * FROM attributes WHERE (NOT a AND (attributes.node_id = 1234))"
1370
1370
  end
1371
1371
 
1372
1372
  it "should support an order option" do
@@ -1555,7 +1555,7 @@ describe Sequel::Model, "one_to_many" do
1555
1555
  ds.filter(:b=>2)
1556
1556
  end
1557
1557
  @c2.new(:id => 1234).remove_all_attributes
1558
- MODEL_DB.sqls.should == ['UPDATE attributes SET node_id = NULL WHERE ((node_id = 1234) AND (a = 1) AND (b = 2))']
1558
+ MODEL_DB.sqls.should == ['UPDATE attributes SET node_id = NULL WHERE ((a = 1) AND (node_id = 1234) AND (b = 2))']
1559
1559
  end
1560
1560
 
1561
1561
  it "should have the remove_all_ method respect the :primary_key option" do
@@ -1924,6 +1924,19 @@ describe Sequel::Model, "many_to_many" do
1924
1924
  MODEL_DB.sqls.should == ['SELECT * FROM attributes NATURAL JOIN an WHERE ((an.nodeid = 1234) AND (xxx = 555)) ORDER BY a LIMIT 10']
1925
1925
  end
1926
1926
 
1927
+ it "should support a :dataset option that accepts the reflection as an argument" do
1928
+ c1 = @c1
1929
+ @c2.many_to_many :attributes, :class => @c1, :dataset=>lambda{|opts| opts.associated_dataset.join_table(:natural, :an).filter(:an__nodeid=>pk)}, :order=> :a, :limit=>10, :select=>nil do |ds|
1930
+ ds.filter(:xxx => @xxx)
1931
+ end
1932
+
1933
+ n = @c2.new(:id => 1234)
1934
+ n.xxx = 555
1935
+ n.attributes_dataset.sql.should == 'SELECT * FROM attributes NATURAL JOIN an WHERE ((an.nodeid = 1234) AND (xxx = 555)) ORDER BY a LIMIT 10'
1936
+ n.attributes.should == [@c1.load({})]
1937
+ MODEL_DB.sqls.should == ['SELECT * FROM attributes NATURAL JOIN an WHERE ((an.nodeid = 1234) AND (xxx = 555)) ORDER BY a LIMIT 10']
1938
+ end
1939
+
1927
1940
  it "should support a :limit option" do
1928
1941
  @c2.many_to_many :attributes, :class => @c1 , :limit=>10
1929
1942
  @c2.new(:id => 1234).attributes_dataset.sql.should == 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON ((attributes_nodes.attribute_id = attributes.id) AND (attributes_nodes.node_id = 1234)) LIMIT 10'
@@ -70,40 +70,80 @@ describe Sequel::Model::DatasetMethods, "#to_hash" do
70
70
  end
71
71
  end
72
72
 
73
- describe Sequel::Model::DatasetMethods, "#join_table" do
73
+ describe Sequel::Model::DatasetMethods do
74
74
  before do
75
75
  @c = Class.new(Sequel::Model(:items))
76
+ @c.columns :id
77
+ @c.db.reset
76
78
  end
77
79
 
78
- specify "should allow use to use a model class when joining" do
80
+ specify "#join_table should allow use to use a model class when joining" do
79
81
  @c.join(Class.new(Sequel::Model(:categories)), :item_id => :id).sql.should == 'SELECT * FROM items INNER JOIN categories ON (categories.item_id = items.id)'
80
82
  end
81
83
 
82
- specify "should handle model classes that aren't simple selects using a subselect" do
84
+ specify "#join_table should handle model classes that aren't simple selects using a subselect" do
83
85
  @c.join(Class.new(Sequel::Model(MODEL_DB[:categories].where(:foo=>1))), :item_id => :id).sql.should == 'SELECT * FROM items INNER JOIN (SELECT * FROM categories WHERE (foo = 1)) AS t1 ON (t1.item_id = items.id)'
84
86
  end
85
- end
86
-
87
- describe Sequel::Model::DatasetMethods, "#graph" do
88
- before do
89
- @c = Class.new(Sequel::Model(:items))
90
- @c.columns :id
91
- end
92
87
 
93
- specify "should allow use to use a model class when joining" do
88
+ specify "#graph should allow use to use a model class when joining" do
94
89
  c = Class.new(Sequel::Model(:categories))
95
90
  c.columns :id
96
91
  @c.graph(c, :item_id => :id).sql.should == 'SELECT items.id, categories.id AS categories_id FROM items LEFT OUTER JOIN categories ON (categories.item_id = items.id)'
97
92
  end
98
- end
99
93
 
100
- describe Sequel::Model::DatasetMethods, "#insert_sql" do
101
- before do
102
- @c = Class.new(Sequel::Model(:items))
103
- @c.columns :id
94
+ specify "#insert_sql should handle a single model instance as an argument" do
95
+ @c.insert_sql(@c.load(:id=>1)).should == 'INSERT INTO items (id) VALUES (1)'
104
96
  end
105
97
 
106
- specify "should handle a single model instance as an argument" do
107
- @c.insert_sql(@c.load(:id=>1)).should == 'INSERT INTO items (id) VALUES (1)'
98
+ specify "#first should handle no primary key" do
99
+ @c.no_primary_key
100
+ @c.first.should be_a_kind_of(@c)
101
+ @c.db.sqls.should == ['SELECT * FROM items LIMIT 1']
102
+ end
103
+
104
+ specify "#last should reverse order by primary key if not already ordered" do
105
+ @c.last.should be_a_kind_of(@c)
106
+ @c.db.sqls.should == ['SELECT * FROM items ORDER BY id DESC LIMIT 1']
107
+ @c.where(:id=>2).last(:foo=>2){{bar=>3}}.should be_a_kind_of(@c)
108
+ @c.db.sqls.should == ['SELECT * FROM items WHERE ((id = 2) AND (bar = 3) AND (foo = 2)) ORDER BY id DESC LIMIT 1']
109
+ end
110
+
111
+ specify "#last should use existing order if there is one" do
112
+ @c.order(:foo).last.should be_a_kind_of(@c)
113
+ @c.db.sqls.should == ['SELECT * FROM items ORDER BY foo DESC LIMIT 1']
114
+ end
115
+
116
+ specify "#last should handle a composite primary key" do
117
+ @c.set_primary_key [:id1, :id2]
118
+ @c.last.should be_a_kind_of(@c)
119
+ @c.db.sqls.should == ['SELECT * FROM items ORDER BY id1 DESC, id2 DESC LIMIT 1']
120
+ end
121
+
122
+ specify "#last should raise an error if no primary key" do
123
+ @c.no_primary_key
124
+ proc{@c.last}.should raise_error(Sequel::Error)
125
+ end
126
+
127
+ specify "#paged_each should order by primary key if not already ordered" do
128
+ @c.paged_each{|r| r.should be_a_kind_of(@c)}
129
+ @c.db.sqls.should == ['BEGIN', 'SELECT * FROM items ORDER BY id LIMIT 1000 OFFSET 0', 'COMMIT']
130
+ @c.paged_each(:rows_per_fetch=>5){|r|}
131
+ @c.db.sqls.should == ['BEGIN', 'SELECT * FROM items ORDER BY id LIMIT 5 OFFSET 0', 'COMMIT']
132
+ end
133
+
134
+ specify "#paged_each should use existing order if there is one" do
135
+ @c.order(:foo).paged_each{|r| r.should be_a_kind_of(@c)}
136
+ @c.db.sqls.should == ['BEGIN', 'SELECT * FROM items ORDER BY foo LIMIT 1000 OFFSET 0', 'COMMIT']
137
+ end
138
+
139
+ specify "#paged_each should handle a composite primary key" do
140
+ @c.set_primary_key [:id1, :id2]
141
+ @c.paged_each{|r| r.should be_a_kind_of(@c)}
142
+ @c.db.sqls.should == ['BEGIN', 'SELECT * FROM items ORDER BY id1, id2 LIMIT 1000 OFFSET 0', 'COMMIT']
143
+ end
144
+
145
+ specify "#paged_each should raise an error if no primary key" do
146
+ @c.no_primary_key
147
+ proc{@c.paged_each{|r| }}.should raise_error(Sequel::Error)
108
148
  end
109
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.43.0
4
+ version: 3.44.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: The Database Toolkit for Ruby
15
15
  email: code@jeremyevans.net
@@ -106,6 +106,7 @@ extra_rdoc_files:
106
106
  - doc/release_notes/3.41.0.txt
107
107
  - doc/release_notes/3.42.0.txt
108
108
  - doc/release_notes/3.43.0.txt
109
+ - doc/release_notes/3.44.0.txt
109
110
  files:
110
111
  - MIT-LICENSE
111
112
  - CHANGELOG
@@ -186,6 +187,7 @@ files:
186
187
  - doc/release_notes/3.41.0.txt
187
188
  - doc/release_notes/3.42.0.txt
188
189
  - doc/release_notes/3.43.0.txt
190
+ - doc/release_notes/3.44.0.txt
189
191
  - doc/sharding.rdoc
190
192
  - doc/sql.rdoc
191
193
  - doc/validations.rdoc