sequel 4.11.0 → 4.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +32 -0
  3. data/Rakefile +1 -5
  4. data/doc/opening_databases.rdoc +5 -1
  5. data/doc/release_notes/4.12.0.txt +105 -0
  6. data/lib/sequel/adapters/jdbc.rb +1 -0
  7. data/lib/sequel/adapters/oracle.rb +1 -0
  8. data/lib/sequel/adapters/postgres.rb +17 -8
  9. data/lib/sequel/adapters/shared/cubrid.rb +2 -1
  10. data/lib/sequel/adapters/shared/db2.rb +1 -0
  11. data/lib/sequel/adapters/shared/mssql.rb +1 -0
  12. data/lib/sequel/adapters/shared/postgres.rb +23 -2
  13. data/lib/sequel/adapters/shared/sqlanywhere.rb +1 -0
  14. data/lib/sequel/adapters/sqlite.rb +11 -5
  15. data/lib/sequel/database/query.rb +14 -1
  16. data/lib/sequel/dataset/prepared_statements.rb +2 -1
  17. data/lib/sequel/dataset/query.rb +48 -37
  18. data/lib/sequel/dataset/sql.rb +0 -39
  19. data/lib/sequel/extensions/pg_interval.rb +1 -1
  20. data/lib/sequel/extensions/pg_static_cache_updater.rb +11 -5
  21. data/lib/sequel/model/associations.rb +2 -2
  22. data/lib/sequel/plugins/auto_validations.rb +16 -4
  23. data/lib/sequel/plugins/hook_class_methods.rb +1 -1
  24. data/lib/sequel/plugins/nested_attributes.rb +72 -59
  25. data/lib/sequel/plugins/prepared_statements.rb +16 -5
  26. data/lib/sequel/plugins/prepared_statements_associations.rb +14 -0
  27. data/lib/sequel/sql.rb +2 -43
  28. data/lib/sequel/version.rb +1 -1
  29. data/spec/adapters/postgres_spec.rb +49 -20
  30. data/spec/bin_spec.rb +2 -2
  31. data/spec/core/dataset_spec.rb +18 -6
  32. data/spec/core/schema_spec.rb +2 -1
  33. data/spec/extensions/auto_validations_spec.rb +23 -2
  34. data/spec/extensions/nested_attributes_spec.rb +32 -1
  35. data/spec/extensions/pg_static_cache_updater_spec.rb +12 -0
  36. data/spec/extensions/prepared_statements_associations_spec.rb +17 -17
  37. data/spec/extensions/prepared_statements_spec.rb +11 -8
  38. data/spec/integration/plugin_test.rb +43 -0
  39. data/spec/integration/schema_test.rb +7 -0
  40. data/spec/model/eager_loading_spec.rb +9 -0
  41. metadata +4 -2
@@ -5,6 +5,7 @@ describe "prepared_statements plugin" do
5
5
  @db = Sequel.mock(:fetch=>{:id=>1, :name=>'foo', :i=>2}, :autoid=>proc{|sql| 1}, :numrows=>1, :servers=>{:read_only=>{}})
6
6
  @c = Class.new(Sequel::Model(@db[:people]))
7
7
  @c.columns :id, :name, :i
8
+ @columns = "id, name, i"
8
9
  @c.plugin :prepared_statements
9
10
  @p = @c.load(:id=>1, :name=>'foo', :i=>2)
10
11
  @ds = @c.dataset
@@ -13,7 +14,7 @@ describe "prepared_statements plugin" do
13
14
 
14
15
  specify "should correctly lookup by primary key" do
15
16
  @c[1].should == @p
16
- @db.sqls.should == ["SELECT * FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
17
+ @db.sqls.should == ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
17
18
  end
18
19
 
19
20
  shared_examples_for "prepared_statements plugin" do
@@ -29,7 +30,7 @@ describe "prepared_statements plugin" do
29
30
 
30
31
  specify "should correctly create instance" do
31
32
  @c.create(:name=>'foo').should == @c.load(:id=>1, :name=>'foo', :i => 2)
32
- @db.sqls.should == ["INSERT INTO people (name) VALUES ('foo')", "SELECT * FROM people WHERE (id = 1) LIMIT 1"]
33
+ @db.sqls.should == ["INSERT INTO people (name) VALUES ('foo')", "SELECT #{@columns} FROM people WHERE (id = 1) LIMIT 1"]
33
34
  end
34
35
 
35
36
  specify "should correctly create instance if dataset supports insert_select" do
@@ -39,14 +40,15 @@ describe "prepared_statements plugin" do
39
40
  end
40
41
  def insert_select(h)
41
42
  self._fetch = {:id=>1, :name=>'foo', :i => 2}
42
- returning.server(:default).with_sql(:insert_sql, h).first
43
+ ds = opts[:returning] ? self : returning
44
+ ds.server(:default).with_sql(:insert_sql, h).first
43
45
  end
44
46
  def insert_sql(*)
45
- "#{super}#{' RETURNING *' if opts.has_key?(:returning)}"
47
+ "#{super}#{" RETURNING #{opts[:returning] && !opts[:returning].empty? ? opts[:returning].map{|c| literal(c)}.join(', ') : '*'}" if opts.has_key?(:returning)}"
46
48
  end
47
49
  end
48
50
  @c.create(:name=>'foo').should == @c.load(:id=>1, :name=>'foo', :i => 2)
49
- @db.sqls.should == ["INSERT INTO people (name) VALUES ('foo') RETURNING *"]
51
+ @db.sqls.should == ["INSERT INTO people (name) VALUES ('foo') RETURNING #{@columns}"]
50
52
  end
51
53
  end
52
54
 
@@ -54,6 +56,7 @@ describe "prepared_statements plugin" do
54
56
 
55
57
  describe "when #use_prepared_statements_for? returns false" do
56
58
  before do
59
+ @columns = "*"
57
60
  @c.class_eval{def use_prepared_statements_for?(type) false end}
58
61
  end
59
62
 
@@ -63,7 +66,7 @@ describe "prepared_statements plugin" do
63
66
  specify "should work correctly when subclassing" do
64
67
  c = Class.new(@c)
65
68
  c[1].should == c.load(:id=>1, :name=>'foo', :i=>2)
66
- @db.sqls.should == ["SELECT * FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
69
+ @db.sqls.should == ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
67
70
  end
68
71
 
69
72
  describe " with placeholder type specifiers" do
@@ -73,7 +76,7 @@ describe "prepared_statements plugin" do
73
76
 
74
77
  specify "should correctly handle without schema type" do
75
78
  @c[1].should == @p
76
- @db.sqls.should == ["SELECT * FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
79
+ @db.sqls.should == ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
77
80
  end
78
81
 
79
82
  specify "should correctly handle with schema type" do
@@ -92,7 +95,7 @@ describe "prepared_statements plugin" do
92
95
  end
93
96
  end
94
97
  @c[1].should == @p
95
- @db.sqls.should == ["SELECT * FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
98
+ @db.sqls.should == ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"]
96
99
  end
97
100
  end
98
101
  end
@@ -1761,6 +1761,49 @@ describe "Sequel::Plugins::PreparedStatements" do
1761
1761
  end
1762
1762
  end
1763
1763
 
1764
+ describe "Sequel::Plugins::PreparedStatements with schema changes" do
1765
+ before do
1766
+ @db = DB
1767
+ @db.create_table!(:ps_test) do
1768
+ primary_key :id
1769
+ String :name
1770
+ end
1771
+ @c = Class.new(Sequel::Model(@db[:ps_test]))
1772
+ @c.many_to_one :ps_test, :key=>:id, :class=>@c
1773
+ @c.one_to_many :ps_tests, :key=>:id, :class=>@c
1774
+ @c.many_to_many :mps_tests, :left_key=>:id, :right_key=>:id, :class=>@c, :join_table=>:ps_test___x
1775
+ @c.plugin :prepared_statements
1776
+ @c.plugin :prepared_statements_associations
1777
+ end
1778
+ after do
1779
+ @db.drop_table?(:ps_test)
1780
+ end
1781
+
1782
+ it "should handle added columns" do
1783
+ foo = @c.create(:name=>'foo')
1784
+ @c[foo.id].name.should == 'foo'
1785
+ foo.ps_test.name.should == 'foo'
1786
+ foo.ps_tests.map{|x| x.name}.should == %w'foo'
1787
+ foo.mps_tests.map{|x| x.name}.should == %w'foo'
1788
+ foo.update(:name=>'foo2')
1789
+ @c[foo.id].name.should == 'foo2'
1790
+ foo.delete
1791
+ foo.exists?.should == false
1792
+
1793
+ @db.alter_table(:ps_test){add_column :i, Integer}
1794
+
1795
+ foo = @c.create(:name=>'foo')
1796
+ @c[foo.id].name.should == 'foo'
1797
+ foo.ps_test.name.should == 'foo'
1798
+ foo.ps_tests.map{|x| x.name}.should == %w'foo'
1799
+ foo.mps_tests.map{|x| x.name}.should == %w'foo'
1800
+ foo.update(:name=>'foo2')
1801
+ @c[foo.id].name.should == 'foo2'
1802
+ foo.delete
1803
+ foo.exists?.should == false
1804
+ end
1805
+ end
1806
+
1764
1807
  describe "Caching plugins" do
1765
1808
  before(:all) do
1766
1809
  @db = DB
@@ -142,6 +142,13 @@ describe "Database schema parser" do
142
142
  DB.create_table!(:items){FalseClass :number}
143
143
  DB.schema(:items).first.last[:type].should == :boolean
144
144
  end
145
+
146
+ specify "should parse maximum length for string columns" do
147
+ DB.create_table!(:items){String :a, :size=>4}
148
+ DB.schema(:items).first.last[:max_length].should == 4
149
+ DB.create_table!(:items){String :a, :fixed=>true, :size=>3}
150
+ DB.schema(:items).first.last[:max_length].should == 3
151
+ end
145
152
  end if DB.supports_schema_parsing?
146
153
 
147
154
  describe "Database index parsing" do
@@ -762,6 +762,15 @@ describe Sequel::Model, "#eager" do
762
762
  a.first.tracks.should == [EagerTrack.load(:id => 3, :album_id=>1)]
763
763
  DB.sqls.should == []
764
764
  end
765
+
766
+ it "should respect the :limit option on a one_to_many association with an association block" do
767
+ EagerAlbum.one_to_many :tracks, :class=>'EagerTrack', :key=>:album_id, :order=>:name, :limit=>2 do |ds| ds.where(:a=>1) end
768
+ a = EagerAlbum.eager(:tracks).all
769
+ a.should == [EagerAlbum.load(:id => 1, :band_id => 2)]
770
+ DB.sqls.should == ['SELECT * FROM albums', 'SELECT * FROM (SELECT * FROM tracks WHERE ((a = 1) AND (1 = tracks.album_id)) ORDER BY name LIMIT 2) AS t1']
771
+ a.first.tracks.should == [EagerTrack.load(:id => 3, :album_id=>1)]
772
+ DB.sqls.should == []
773
+ end
765
774
 
766
775
  it "should respect the :limit option on a one_to_many association using the :window_function strategy" do
767
776
  def (EagerTrack.dataset).supports_window_functions?() true end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.0
4
+ version: 4.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The Database Toolkit for Ruby
14
14
  email: code@jeremyevans.net
@@ -128,6 +128,7 @@ extra_rdoc_files:
128
128
  - doc/release_notes/4.9.0.txt
129
129
  - doc/release_notes/4.10.0.txt
130
130
  - doc/release_notes/4.11.0.txt
131
+ - doc/release_notes/4.12.0.txt
131
132
  files:
132
133
  - CHANGELOG
133
134
  - MIT-LICENSE
@@ -226,6 +227,7 @@ files:
226
227
  - doc/release_notes/4.1.0.txt
227
228
  - doc/release_notes/4.10.0.txt
228
229
  - doc/release_notes/4.11.0.txt
230
+ - doc/release_notes/4.12.0.txt
229
231
  - doc/release_notes/4.2.0.txt
230
232
  - doc/release_notes/4.3.0.txt
231
233
  - doc/release_notes/4.4.0.txt