sequel 4.9.0 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +79 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/Rakefile +2 -12
  6. data/bin/sequel +1 -0
  7. data/doc/advanced_associations.rdoc +82 -25
  8. data/doc/association_basics.rdoc +21 -22
  9. data/doc/core_extensions.rdoc +1 -1
  10. data/doc/opening_databases.rdoc +7 -0
  11. data/doc/release_notes/4.10.0.txt +226 -0
  12. data/doc/security.rdoc +1 -0
  13. data/doc/testing.rdoc +7 -7
  14. data/doc/transactions.rdoc +8 -0
  15. data/lib/sequel/adapters/jdbc.rb +160 -168
  16. data/lib/sequel/adapters/jdbc/db2.rb +17 -18
  17. data/lib/sequel/adapters/jdbc/derby.rb +5 -28
  18. data/lib/sequel/adapters/jdbc/h2.rb +11 -22
  19. data/lib/sequel/adapters/jdbc/hsqldb.rb +31 -18
  20. data/lib/sequel/adapters/jdbc/jtds.rb +0 -15
  21. data/lib/sequel/adapters/jdbc/oracle.rb +36 -35
  22. data/lib/sequel/adapters/jdbc/postgresql.rb +72 -90
  23. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +18 -16
  24. data/lib/sequel/adapters/jdbc/sqlite.rb +7 -0
  25. data/lib/sequel/adapters/jdbc/sqlserver.rb +10 -30
  26. data/lib/sequel/adapters/jdbc/transactions.rb +5 -6
  27. data/lib/sequel/adapters/openbase.rb +1 -7
  28. data/lib/sequel/adapters/postgres.rb +1 -1
  29. data/lib/sequel/adapters/shared/access.rb +3 -6
  30. data/lib/sequel/adapters/shared/cubrid.rb +24 -9
  31. data/lib/sequel/adapters/shared/db2.rb +13 -5
  32. data/lib/sequel/adapters/shared/firebird.rb +16 -16
  33. data/lib/sequel/adapters/shared/informix.rb +2 -5
  34. data/lib/sequel/adapters/shared/mssql.rb +72 -63
  35. data/lib/sequel/adapters/shared/mysql.rb +72 -40
  36. data/lib/sequel/adapters/shared/oracle.rb +27 -15
  37. data/lib/sequel/adapters/shared/postgres.rb +24 -44
  38. data/lib/sequel/adapters/shared/progress.rb +1 -5
  39. data/lib/sequel/adapters/shared/sqlanywhere.rb +26 -18
  40. data/lib/sequel/adapters/shared/sqlite.rb +21 -6
  41. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +8 -1
  42. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +8 -2
  43. data/lib/sequel/adapters/utils/split_alter_table.rb +8 -0
  44. data/lib/sequel/core.rb +14 -9
  45. data/lib/sequel/database/dataset_defaults.rb +1 -0
  46. data/lib/sequel/database/misc.rb +12 -0
  47. data/lib/sequel/database/query.rb +4 -1
  48. data/lib/sequel/database/schema_methods.rb +3 -2
  49. data/lib/sequel/database/transactions.rb +47 -17
  50. data/lib/sequel/dataset/features.rb +12 -2
  51. data/lib/sequel/dataset/mutation.rb +2 -0
  52. data/lib/sequel/dataset/placeholder_literalizer.rb +12 -4
  53. data/lib/sequel/dataset/prepared_statements.rb +6 -0
  54. data/lib/sequel/dataset/query.rb +1 -1
  55. data/lib/sequel/dataset/sql.rb +132 -70
  56. data/lib/sequel/extensions/columns_introspection.rb +1 -1
  57. data/lib/sequel/extensions/null_dataset.rb +8 -4
  58. data/lib/sequel/extensions/pg_array.rb +4 -4
  59. data/lib/sequel/extensions/pg_row.rb +1 -0
  60. data/lib/sequel/model/associations.rb +468 -188
  61. data/lib/sequel/model/base.rb +88 -13
  62. data/lib/sequel/plugins/association_pks.rb +23 -64
  63. data/lib/sequel/plugins/auto_validations.rb +3 -2
  64. data/lib/sequel/plugins/dataset_associations.rb +1 -3
  65. data/lib/sequel/plugins/many_through_many.rb +18 -65
  66. data/lib/sequel/plugins/pg_array_associations.rb +97 -86
  67. data/lib/sequel/plugins/prepared_statements.rb +2 -1
  68. data/lib/sequel/plugins/prepared_statements_associations.rb +36 -27
  69. data/lib/sequel/plugins/rcte_tree.rb +12 -16
  70. data/lib/sequel/plugins/sharding.rb +21 -3
  71. data/lib/sequel/plugins/single_table_inheritance.rb +2 -1
  72. data/lib/sequel/plugins/subclasses.rb +1 -9
  73. data/lib/sequel/plugins/tactical_eager_loading.rb +9 -0
  74. data/lib/sequel/plugins/tree.rb +2 -2
  75. data/lib/sequel/plugins/validation_class_methods.rb +1 -1
  76. data/lib/sequel/version.rb +1 -1
  77. data/spec/adapters/mssql_spec.rb +57 -15
  78. data/spec/adapters/mysql_spec.rb +11 -0
  79. data/spec/bin_spec.rb +2 -2
  80. data/spec/core/database_spec.rb +38 -4
  81. data/spec/core/dataset_spec.rb +45 -7
  82. data/spec/core/placeholder_literalizer_spec.rb +17 -0
  83. data/spec/core/schema_spec.rb +6 -1
  84. data/spec/extensions/active_model_spec.rb +18 -9
  85. data/spec/extensions/association_pks_spec.rb +20 -18
  86. data/spec/extensions/association_proxies_spec.rb +9 -9
  87. data/spec/extensions/auto_validations_spec.rb +6 -0
  88. data/spec/extensions/columns_introspection_spec.rb +1 -0
  89. data/spec/extensions/constraint_validations_spec.rb +3 -1
  90. data/spec/extensions/many_through_many_spec.rb +191 -111
  91. data/spec/extensions/pg_array_associations_spec.rb +133 -103
  92. data/spec/extensions/prepared_statements_associations_spec.rb +23 -4
  93. data/spec/extensions/rcte_tree_spec.rb +35 -27
  94. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -1
  95. data/spec/extensions/sharding_spec.rb +2 -2
  96. data/spec/extensions/tactical_eager_loading_spec.rb +4 -0
  97. data/spec/extensions/to_dot_spec.rb +1 -0
  98. data/spec/extensions/touch_spec.rb +2 -2
  99. data/spec/integration/associations_test.rb +130 -37
  100. data/spec/integration/dataset_test.rb +17 -0
  101. data/spec/integration/model_test.rb +17 -0
  102. data/spec/integration/schema_test.rb +14 -0
  103. data/spec/integration/transaction_test.rb +25 -1
  104. data/spec/model/association_reflection_spec.rb +63 -24
  105. data/spec/model/associations_spec.rb +104 -57
  106. data/spec/model/base_spec.rb +14 -1
  107. data/spec/model/class_dataset_methods_spec.rb +1 -0
  108. data/spec/model/eager_loading_spec.rb +221 -74
  109. data/spec/model/model_spec.rb +119 -1
  110. metadata +4 -2
@@ -521,7 +521,125 @@ describe Sequel::Model, ".finder" do
521
521
  @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
522
522
  end
523
523
 
524
- specify "should raise error when callign with the wrong arity" do
524
+ specify "should raise error when calling with the wrong arity" do
525
+ @c.finder :foo
526
+ proc{@c.first_foo(1)}.should raise_error
527
+ proc{@c.first_foo(1,2,3)}.should raise_error
528
+ end
529
+ end
530
+
531
+ describe Sequel::Model, ".prepared_finder" do
532
+ before do
533
+ @h = {:id=>1}
534
+ @db = Sequel.mock(:fetch=>@h)
535
+ @db.extend_datasets do
536
+ def select_sql
537
+ sql = super
538
+ sql << ' -- prepared' if is_a?(Sequel::Dataset::PreparedStatementMethods)
539
+ sql
540
+ end
541
+ end
542
+ @c = Class.new(Sequel::Model(@db[:items]))
543
+ @c.instance_eval do
544
+ def foo(a, b)
545
+ where(:bar=>a).order(b)
546
+ end
547
+ end
548
+ @o = @c.load(@h)
549
+ @db.sqls
550
+ end
551
+
552
+ specify "should create a method that calls the method given and returns the first instance" do
553
+ @c.prepared_finder :foo
554
+ @c.first_foo(1, 2).should == @o
555
+ @c.first_foo(3, 4).should == @o
556
+ @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
557
+ end
558
+
559
+ specify "should work correctly when subclassing" do
560
+ @c.prepared_finder(:foo)
561
+ @sc = Class.new(@c)
562
+ @sc.set_dataset :foos
563
+ @db.sqls
564
+ @sc.first_foo(1, 2).should == @sc.load(@h)
565
+ @sc.first_foo(3, 4).should == @sc.load(@h)
566
+ @db.sqls.should == ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
567
+ end
568
+
569
+ specify "should work correctly when dataset is modified" do
570
+ @c.prepared_finder(:foo)
571
+ @c.first_foo(1, 2).should == @o
572
+ @c.set_dataset :foos
573
+ @c.first_foo(3, 4).should == @o
574
+ @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
575
+ end
576
+
577
+ specify "should create a method based on the given block if no method symbol provided" do
578
+ @c.prepared_finder(:name=>:first_foo){|a1| where(:id=>a1).limit(1)}
579
+ @c.first_foo(1).should == @o
580
+ @db.sqls.should == ["SELECT * FROM items WHERE (id = 1) LIMIT 1 -- prepared"]
581
+ end
582
+
583
+ specify "should raise an error if both a block and method symbol given" do
584
+ proc{@c.prepared_finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.should raise_error(Sequel::Error)
585
+ end
586
+
587
+ specify "should raise an error if two option hashes are provided" do
588
+ proc{@c.prepared_finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.should raise_error(Sequel::Error)
589
+ end
590
+
591
+ specify "should support :type option" do
592
+ @c.prepared_finder :foo, :type=>:all
593
+ @c.prepared_finder :foo, :type=>:each
594
+
595
+ a = []
596
+ @c.all_foo(1, 2){|r| a << r}.should == [@o]
597
+ a.should == [@o]
598
+
599
+ a = []
600
+ @c.each_foo(3, 4){|r| a << r}
601
+ a.should == [@o]
602
+
603
+ @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 -- prepared"]
604
+ end
605
+
606
+ specify "should support :name option" do
607
+ @c.prepared_finder :foo, :name=>:find_foo
608
+ @c.find_foo(1, 2).should == @o
609
+ @c.find_foo(3, 4).should == @o
610
+ @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
611
+ end
612
+
613
+ specify "should support :arity option" do
614
+ def @c.foobar(*b)
615
+ ds = dataset
616
+ b.each_with_index do |a, i|
617
+ ds = ds.where(i=>a)
618
+ end
619
+ ds
620
+ end
621
+ @c.prepared_finder :foobar, :arity=>1, :name=>:find_foobar_1
622
+ @c.prepared_finder :foobar, :arity=>2, :name=>:find_foobar_2
623
+ @c.find_foobar_1(:a)
624
+ @c.find_foobar_2(:a, :b)
625
+ @db.sqls.should == ["SELECT * FROM items WHERE (0 = a) LIMIT 1 -- prepared", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1 -- prepared"]
626
+ end
627
+
628
+ specify "should support :mod option" do
629
+ m = Module.new
630
+ @c.prepared_finder :foo, :mod=>m
631
+ proc{@c.first_foo}.should raise_error
632
+ @c.extend m
633
+ @c.first_foo(1, 2).should == @o
634
+ @c.first_foo(3, 4).should == @o
635
+ @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
636
+ end
637
+
638
+ specify "should handle models with names" do
639
+ def @c.name; 'foobar' end
640
+ @c.prepared_finder :foo
641
+ @c.first_foo(1, 2).should == @o
642
+ @db.sqls.should == ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared"]
525
643
  end
526
644
  end
527
645
 
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.9.0
4
+ version: 4.10.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-04-01 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The Database Toolkit for Ruby
14
14
  email: code@jeremyevans.net
@@ -126,6 +126,7 @@ extra_rdoc_files:
126
126
  - doc/release_notes/4.7.0.txt
127
127
  - doc/release_notes/4.8.0.txt
128
128
  - doc/release_notes/4.9.0.txt
129
+ - doc/release_notes/4.10.0.txt
129
130
  files:
130
131
  - CHANGELOG
131
132
  - MIT-LICENSE
@@ -222,6 +223,7 @@ files:
222
223
  - doc/release_notes/3.9.0.txt
223
224
  - doc/release_notes/4.0.0.txt
224
225
  - doc/release_notes/4.1.0.txt
226
+ - doc/release_notes/4.10.0.txt
225
227
  - doc/release_notes/4.2.0.txt
226
228
  - doc/release_notes/4.3.0.txt
227
229
  - doc/release_notes/4.4.0.txt