sequel 5.39.0 → 5.63.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +308 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +57 -25
  5. data/bin/sequel +11 -3
  6. data/doc/advanced_associations.rdoc +13 -13
  7. data/doc/association_basics.rdoc +89 -24
  8. data/doc/cheat_sheet.rdoc +11 -3
  9. data/doc/migration.rdoc +12 -6
  10. data/doc/model_hooks.rdoc +1 -1
  11. data/doc/object_model.rdoc +8 -8
  12. data/doc/opening_databases.rdoc +18 -11
  13. data/doc/postgresql.rdoc +16 -8
  14. data/doc/querying.rdoc +5 -3
  15. data/doc/release_notes/5.40.0.txt +40 -0
  16. data/doc/release_notes/5.41.0.txt +25 -0
  17. data/doc/release_notes/5.42.0.txt +136 -0
  18. data/doc/release_notes/5.43.0.txt +98 -0
  19. data/doc/release_notes/5.44.0.txt +32 -0
  20. data/doc/release_notes/5.45.0.txt +34 -0
  21. data/doc/release_notes/5.46.0.txt +87 -0
  22. data/doc/release_notes/5.47.0.txt +59 -0
  23. data/doc/release_notes/5.48.0.txt +14 -0
  24. data/doc/release_notes/5.49.0.txt +59 -0
  25. data/doc/release_notes/5.50.0.txt +78 -0
  26. data/doc/release_notes/5.51.0.txt +47 -0
  27. data/doc/release_notes/5.52.0.txt +87 -0
  28. data/doc/release_notes/5.53.0.txt +23 -0
  29. data/doc/release_notes/5.54.0.txt +27 -0
  30. data/doc/release_notes/5.55.0.txt +21 -0
  31. data/doc/release_notes/5.56.0.txt +51 -0
  32. data/doc/release_notes/5.57.0.txt +23 -0
  33. data/doc/release_notes/5.58.0.txt +31 -0
  34. data/doc/release_notes/5.59.0.txt +73 -0
  35. data/doc/release_notes/5.60.0.txt +22 -0
  36. data/doc/release_notes/5.61.0.txt +43 -0
  37. data/doc/release_notes/5.62.0.txt +132 -0
  38. data/doc/release_notes/5.63.0.txt +33 -0
  39. data/doc/schema_modification.rdoc +1 -1
  40. data/doc/security.rdoc +9 -9
  41. data/doc/sql.rdoc +27 -15
  42. data/doc/testing.rdoc +22 -11
  43. data/doc/transactions.rdoc +6 -6
  44. data/doc/virtual_rows.rdoc +2 -2
  45. data/lib/sequel/adapters/ado/access.rb +1 -1
  46. data/lib/sequel/adapters/ado.rb +17 -17
  47. data/lib/sequel/adapters/amalgalite.rb +3 -5
  48. data/lib/sequel/adapters/ibmdb.rb +2 -2
  49. data/lib/sequel/adapters/jdbc/derby.rb +8 -0
  50. data/lib/sequel/adapters/jdbc/h2.rb +60 -10
  51. data/lib/sequel/adapters/jdbc/hsqldb.rb +6 -0
  52. data/lib/sequel/adapters/jdbc/postgresql.rb +4 -4
  53. data/lib/sequel/adapters/jdbc.rb +16 -18
  54. data/lib/sequel/adapters/mysql.rb +80 -67
  55. data/lib/sequel/adapters/mysql2.rb +54 -49
  56. data/lib/sequel/adapters/odbc.rb +6 -2
  57. data/lib/sequel/adapters/oracle.rb +3 -3
  58. data/lib/sequel/adapters/postgres.rb +83 -40
  59. data/lib/sequel/adapters/shared/access.rb +11 -1
  60. data/lib/sequel/adapters/shared/db2.rb +30 -0
  61. data/lib/sequel/adapters/shared/mssql.rb +58 -7
  62. data/lib/sequel/adapters/shared/mysql.rb +40 -2
  63. data/lib/sequel/adapters/shared/oracle.rb +76 -0
  64. data/lib/sequel/adapters/shared/postgres.rb +418 -174
  65. data/lib/sequel/adapters/shared/sqlanywhere.rb +10 -0
  66. data/lib/sequel/adapters/shared/sqlite.rb +102 -11
  67. data/lib/sequel/adapters/sqlanywhere.rb +1 -1
  68. data/lib/sequel/adapters/sqlite.rb +60 -18
  69. data/lib/sequel/adapters/tinytds.rb +1 -1
  70. data/lib/sequel/adapters/utils/columns_limit_1.rb +22 -0
  71. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  72. data/lib/sequel/ast_transformer.rb +6 -0
  73. data/lib/sequel/connection_pool/sharded_single.rb +5 -7
  74. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -1
  75. data/lib/sequel/connection_pool/single.rb +6 -8
  76. data/lib/sequel/connection_pool/threaded.rb +8 -8
  77. data/lib/sequel/connection_pool/timed_queue.rb +257 -0
  78. data/lib/sequel/connection_pool.rb +47 -30
  79. data/lib/sequel/core.rb +28 -18
  80. data/lib/sequel/database/connecting.rb +26 -2
  81. data/lib/sequel/database/misc.rb +69 -14
  82. data/lib/sequel/database/query.rb +38 -1
  83. data/lib/sequel/database/schema_generator.rb +45 -52
  84. data/lib/sequel/database/schema_methods.rb +17 -1
  85. data/lib/sequel/dataset/actions.rb +107 -13
  86. data/lib/sequel/dataset/features.rb +20 -0
  87. data/lib/sequel/dataset/misc.rb +1 -1
  88. data/lib/sequel/dataset/prepared_statements.rb +2 -0
  89. data/lib/sequel/dataset/query.rb +118 -16
  90. data/lib/sequel/dataset/sql.rb +177 -47
  91. data/lib/sequel/extensions/_model_pg_row.rb +0 -12
  92. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  93. data/lib/sequel/extensions/any_not_empty.rb +1 -1
  94. data/lib/sequel/extensions/async_thread_pool.rb +438 -0
  95. data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
  96. data/lib/sequel/extensions/blank.rb +8 -0
  97. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  98. data/lib/sequel/extensions/core_refinements.rb +36 -11
  99. data/lib/sequel/extensions/date_arithmetic.rb +71 -31
  100. data/lib/sequel/extensions/date_parse_input_handler.rb +67 -0
  101. data/lib/sequel/extensions/datetime_parse_to_time.rb +5 -1
  102. data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
  103. data/lib/sequel/extensions/eval_inspect.rb +2 -0
  104. data/lib/sequel/extensions/inflector.rb +9 -1
  105. data/lib/sequel/extensions/is_distinct_from.rb +141 -0
  106. data/lib/sequel/extensions/looser_typecasting.rb +3 -0
  107. data/lib/sequel/extensions/migration.rb +7 -2
  108. data/lib/sequel/extensions/named_timezones.rb +26 -6
  109. data/lib/sequel/extensions/pagination.rb +1 -1
  110. data/lib/sequel/extensions/pg_array.rb +23 -3
  111. data/lib/sequel/extensions/pg_array_ops.rb +2 -2
  112. data/lib/sequel/extensions/pg_auto_parameterize.rb +478 -0
  113. data/lib/sequel/extensions/pg_enum.rb +1 -1
  114. data/lib/sequel/extensions/pg_extended_date_support.rb +28 -25
  115. data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
  116. data/lib/sequel/extensions/pg_hstore.rb +6 -1
  117. data/lib/sequel/extensions/pg_hstore_ops.rb +53 -3
  118. data/lib/sequel/extensions/pg_inet.rb +10 -11
  119. data/lib/sequel/extensions/pg_inet_ops.rb +1 -1
  120. data/lib/sequel/extensions/pg_interval.rb +45 -19
  121. data/lib/sequel/extensions/pg_json.rb +13 -15
  122. data/lib/sequel/extensions/pg_json_ops.rb +73 -2
  123. data/lib/sequel/extensions/pg_loose_count.rb +3 -1
  124. data/lib/sequel/extensions/pg_multirange.rb +367 -0
  125. data/lib/sequel/extensions/pg_range.rb +10 -23
  126. data/lib/sequel/extensions/pg_range_ops.rb +37 -9
  127. data/lib/sequel/extensions/pg_row.rb +19 -13
  128. data/lib/sequel/extensions/pg_row_ops.rb +1 -1
  129. data/lib/sequel/extensions/query.rb +2 -0
  130. data/lib/sequel/extensions/s.rb +2 -1
  131. data/lib/sequel/extensions/schema_dumper.rb +13 -2
  132. data/lib/sequel/extensions/server_block.rb +8 -12
  133. data/lib/sequel/extensions/sql_comments.rb +110 -3
  134. data/lib/sequel/extensions/sql_log_normalizer.rb +108 -0
  135. data/lib/sequel/extensions/sqlite_json_ops.rb +255 -0
  136. data/lib/sequel/extensions/string_agg.rb +1 -1
  137. data/lib/sequel/extensions/string_date_time.rb +19 -23
  138. data/lib/sequel/extensions/symbol_aref.rb +2 -0
  139. data/lib/sequel/model/associations.rb +325 -96
  140. data/lib/sequel/model/base.rb +51 -27
  141. data/lib/sequel/model/errors.rb +10 -1
  142. data/lib/sequel/model/inflections.rb +1 -1
  143. data/lib/sequel/model/plugins.rb +5 -0
  144. data/lib/sequel/plugins/association_proxies.rb +2 -0
  145. data/lib/sequel/plugins/async_thread_pool.rb +39 -0
  146. data/lib/sequel/plugins/auto_restrict_eager_graph.rb +62 -0
  147. data/lib/sequel/plugins/auto_validations.rb +87 -15
  148. data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
  149. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  150. data/lib/sequel/plugins/column_encryption.rb +728 -0
  151. data/lib/sequel/plugins/composition.rb +10 -4
  152. data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
  153. data/lib/sequel/plugins/constraint_validations.rb +2 -1
  154. data/lib/sequel/plugins/dataset_associations.rb +4 -1
  155. data/lib/sequel/plugins/dirty.rb +1 -1
  156. data/lib/sequel/plugins/enum.rb +124 -0
  157. data/lib/sequel/plugins/finder.rb +3 -1
  158. data/lib/sequel/plugins/insert_conflict.rb +4 -0
  159. data/lib/sequel/plugins/instance_specific_default.rb +1 -1
  160. data/lib/sequel/plugins/json_serializer.rb +39 -24
  161. data/lib/sequel/plugins/lazy_attributes.rb +3 -0
  162. data/lib/sequel/plugins/list.rb +3 -1
  163. data/lib/sequel/plugins/many_through_many.rb +108 -9
  164. data/lib/sequel/plugins/nested_attributes.rb +12 -7
  165. data/lib/sequel/plugins/pg_array_associations.rb +56 -38
  166. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +3 -1
  167. data/lib/sequel/plugins/prepared_statements.rb +10 -1
  168. data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
  169. data/lib/sequel/plugins/rcte_tree.rb +27 -19
  170. data/lib/sequel/plugins/require_valid_schema.rb +67 -0
  171. data/lib/sequel/plugins/serialization.rb +9 -3
  172. data/lib/sequel/plugins/serialization_modification_detection.rb +2 -1
  173. data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
  174. data/lib/sequel/plugins/sql_comments.rb +189 -0
  175. data/lib/sequel/plugins/static_cache.rb +1 -1
  176. data/lib/sequel/plugins/subclasses.rb +28 -11
  177. data/lib/sequel/plugins/tactical_eager_loading.rb +23 -10
  178. data/lib/sequel/plugins/timestamps.rb +1 -1
  179. data/lib/sequel/plugins/unused_associations.rb +521 -0
  180. data/lib/sequel/plugins/update_or_create.rb +1 -1
  181. data/lib/sequel/plugins/validate_associated.rb +22 -12
  182. data/lib/sequel/plugins/validation_helpers.rb +38 -11
  183. data/lib/sequel/plugins/xml_serializer.rb +1 -1
  184. data/lib/sequel/sql.rb +1 -1
  185. data/lib/sequel/timezones.rb +12 -14
  186. data/lib/sequel/version.rb +1 -1
  187. metadata +97 -43
@@ -41,7 +41,7 @@ As is the code to add a related album to an artist:
41
41
 
42
42
  @artist.add_album(name: 'RF')
43
43
 
44
- It also makes it easier to creating queries that use joins based on the association:
44
+ It also makes it easier to create queries that use joins based on the association:
45
45
 
46
46
  Artist.association_join(:albums)
47
47
  # SELECT * FROM artists
@@ -63,8 +63,8 @@ It ships with additional association types via plugins.
63
63
 
64
64
  The many_to_one association is used when the table for the current class
65
65
  contains a foreign key that references the primary key in the table for the
66
- associated class. It is named because there can be many rows in the current
67
- table for each row in the associated table.
66
+ associated class. It is named 'many_to_one' because there can be many rows
67
+ in the current table for each row in the associated table.
68
68
 
69
69
  # Database schema:
70
70
  # albums artists
@@ -81,8 +81,8 @@ table for each row in the associated table.
81
81
 
82
82
  The one_to_many association is used when the table for the associated class
83
83
  contains a foreign key that references the primary key in the table for the
84
- current class. It is named because for each row in the current table there
85
- can be many rows in the associated table:
84
+ current class. It is named 'one_to_many' because for each row in the
85
+ current table there can be many rows in the associated table:
86
86
 
87
87
  The one_to_one association can be thought of as a subset of the one_to_many association,
88
88
  but where there can only be either 0 or 1 records in the associated table. This is
@@ -320,11 +320,11 @@ Associations are cached after being retrieved:
320
320
  @album.artists # Cached - No Database Query
321
321
 
322
322
  You can choose to ignore the cached versions and do a database query to
323
- retrieve results by passing a :reload=>true option to the association method:
323
+ retrieve results by passing a <tt>reload: true</tt> option to the association method:
324
324
 
325
325
  @album.artists # Not cached - Database Query
326
326
  @album.artists # Cached - No Database Query
327
- @album.artists(:reload=>true) # Ignore cache - Database Query
327
+ @album.artists(reload: true) # Ignore cache - Database Query
328
328
 
329
329
  If you reload/refresh the object, it will automatically clear the
330
330
  associations cache for the object:
@@ -342,9 +342,15 @@ instance method:
342
342
  @album.artists # [<Artist ...>, ...]
343
343
  @album.associations[:artists] # [<Artist ...>, ...]
344
344
 
345
+ === Code Reloading
346
+
347
+ When declaring associations, Sequel caches association metadata in the association reflection. If you're doing any code reloading that doesn't involve restarting the related process, you should disable caching of the association reflection, to avoid stale model classes still being referenced after reloading:
348
+
349
+ Sequel::Model.cache_associations = false
350
+
345
351
  == Dataset Method
346
352
 
347
- In addition to the above methods, associations also add a instance method
353
+ In addition to the above methods, associations also add an instance method
348
354
  ending in +_dataset+ that returns a dataset representing the objects in the associated table:
349
355
 
350
356
  @album.artist_id
@@ -532,14 +538,14 @@ Which could be created using the following Sequel code:
532
538
  DB.create_table(:artists) do
533
539
  # Primary key must be set explicitly
534
540
  primary_key :id
535
- String :name, :null=>false, :unique=>true
541
+ String :name, null: false, unique: true
536
542
  end
537
543
  DB.create_table(:albums) do
538
544
  primary_key :id
539
545
  # Table that foreign key references needs to be set explicitly
540
546
  # for a database foreign key reference to be created.
541
- foreign_key :artist_id, :artists, :null=>false
542
- String :name, :null=>false, :unique=>true
547
+ foreign_key :artist_id, :artists, null: false
548
+ String :name, null: false, unique: true
543
549
  end
544
550
 
545
551
  If you already had a schema such as:
@@ -552,7 +558,7 @@ If you already had a schema such as:
552
558
  Then you just need to add the column:
553
559
 
554
560
  DB.alter_table(:albums) do
555
- add_foreign_key :artist_id, :artists, :null=>false
561
+ add_foreign_key :artist_id, :artists, null: false
556
562
  end
557
563
 
558
564
  === many_to_many
@@ -588,11 +594,11 @@ wanted to add an albums_artists join table to create the following schema:
588
594
 
589
595
  You could use the following Sequel code:
590
596
 
591
- DB.create_join_table(:album_id=>:albums, :artist_id=>:artists)
597
+ DB.create_join_table(album_id: :albums, artist_id: :artists)
592
598
  # or
593
599
  DB.create_table(:albums_artists) do
594
- foreign_key :album_id, :albums, :null=>false
595
- foreign_key :artist_id, :artists, :null=>false
600
+ foreign_key :album_id, :albums, null: false
601
+ foreign_key :artist_id, :artists, null: false
596
602
  primary_key [:album_id, :artist_id]
597
603
  index [:artist_id, :album_id]
598
604
  end
@@ -713,7 +719,7 @@ saving the passed in (or newly created) object. However, to avoid
713
719
  silent failures of these methods, they explicitly raise exceptions
714
720
  even when raise_on_save_failure is false for the associated model.
715
721
  You can disable this behavior (i.e. return nil instead of raising
716
- exceptions on a save failure) by setting the <tt>:raise_on_save_failure=>false</tt>
722
+ exceptions on a save failure) by setting the <tt>raise_on_save_failure: false</tt>
717
723
  option for the association.
718
724
 
719
725
  === remove_<i>association</i>(object_to_disassociate) (e.g. remove_album) [+one_to_many+ and +many_to_many+]
@@ -826,6 +832,8 @@ you also wanted to handle the Artist#add_album method:
826
832
  end)
827
833
  end
828
834
 
835
+ You can set this to +nil+ to not create a add_<i>association</i> method.
836
+
829
837
  === :remover (\_remove_<i>association</i> method)
830
838
 
831
839
  Continuing with the same example, here's how you would handle the same case if
@@ -837,6 +845,8 @@ you also wanted to handle the Artist#remove_album method:
837
845
  end)
838
846
  end
839
847
 
848
+ You can set this to +nil+ to not create a remove_<i>association</i> method.
849
+
840
850
  === :clearer (\_remove_all_<i>association</i> method)
841
851
 
842
852
  Continuing with the same example, here's how you would handle the same case if
@@ -850,6 +860,22 @@ you also wanted to handle the Artist#remove_all_albums method:
850
860
  end)
851
861
  end
852
862
 
863
+ You can set this to +nil+ to not create a remove_all_<i>association</i> method.
864
+
865
+ === :no_dataset_method
866
+
867
+ Setting this to true will not result in the <i>association</i>_dataset method
868
+ not being defined. This can save memory if you only use the <i>association</i>
869
+ method and do not call the <i>association</i>_dataset method directly or
870
+ indirectly.
871
+
872
+ === :no_association_method
873
+
874
+ Setting this to true will not result in the <i>association</i> method
875
+ not being defined. This can save memory if you only use the
876
+ <i>association</i>_dataset method and do not call the <i>association</i> method
877
+ directly or indirectly.
878
+
853
879
  == Association Options
854
880
 
855
881
  Sequel's associations mostly share the same options. For ease of understanding,
@@ -961,7 +987,7 @@ If you do not use a hash or array of two element arrays, you should use the
961
987
  :graph_conditions, :graph_only_conditions, or :graph_block option or you will not
962
988
  be able to use eager_graph or association_join with the association.
963
989
 
964
- Artist.one_to_many :good_albums, class: :Album, conditions: {:good=>true}
990
+ Artist.one_to_many :good_albums, class: :Album, conditions: {good: true}
965
991
  @artist.good_albums
966
992
  # SELECT * FROM albums WHERE ((artist_id = 1) AND (good IS TRUE))
967
993
 
@@ -1087,7 +1113,7 @@ already applied, and the proc should return a modified copy of this dataset.
1087
1113
  Here's an example of an association of songs to artists through lyrics, where
1088
1114
  the artist can perform any one of four tasks for the lyric:
1089
1115
 
1090
- Album.one_to_many :songs, dataset: (lambda do |r|
1116
+ Artist.one_to_many :songs, dataset: (lambda do |r|
1091
1117
  r.associated_dataset.select_all(:songs).
1092
1118
  join(:lyrics, id: :lyricid, id=>[:composer_id, :arranger_id, :vocalist_id, :lyricist_id])
1093
1119
  end)
@@ -1142,10 +1168,27 @@ join of the join table and the associated table, whereas this option just
1142
1168
  applies to the join table. It can be used to make sure that filters are used
1143
1169
  when deleting.
1144
1170
 
1145
- Artist.many_to_many :lead_guitar_albums, class: :Album, :join_table_block=>(lambda do |ds|
1171
+ Artist.many_to_many :lead_guitar_albums, class: :Album, join_table_block: (lambda do |ds|
1146
1172
  ds.where(instrument_id: 5)
1147
1173
  end)
1148
1174
 
1175
+ ==== :join_table_db [+many_to_many+, +one_through_one+]
1176
+
1177
+ A Sequel::Database to use for the join table. Specifying this option switches the
1178
+ loading to use a separate query for the join table. This is useful if the
1179
+ join table is not located in the same database as the associated table, or
1180
+ if the database account with access to the associated table doesn't have
1181
+ access to the join table.
1182
+
1183
+ For example, if the Album class uses a different Sequel::Database than the Artist
1184
+ class, and the join table is in the database that the Artist class uses:
1185
+
1186
+ Artist.many_to_many :lead_guitar_albums, class: :Album, join_table_db: Artist.db
1187
+
1188
+ This option also affects the add/remove/remove_all methods, by changing
1189
+ which database is used for inserts/deletes from the join table (add/remove/remove_all
1190
+ defaults to use the current model's database instead of the associated model's database).
1191
+
1149
1192
  === Callback Options
1150
1193
 
1151
1194
  All callbacks can be specified as a Symbol, Proc, or array of both/either
@@ -1433,7 +1476,7 @@ at least the following keys:
1433
1476
  Example:
1434
1477
 
1435
1478
  Artist.one_to_many :self_title_albums, class: :Album,
1436
- :eager_grapher=>(lambda do |eo|
1479
+ eager_grapher: (lambda do |eo|
1437
1480
  eo[:self].graph(:albums, {artist_id: :id, name: :name},
1438
1481
  table_alias: eo[:table_alias], implicit_qualifier: eo[:implicit_qualifier])
1439
1482
  end)
@@ -1638,9 +1681,8 @@ For +many_to_one+ and +one_to_one+ associations, do not add a setter method.
1638
1681
  For +one_to_many+ and +many_to_many+, do not add the add_<i>association</i>,
1639
1682
  remove_<i>association</i>, or remove_all_<i>association</i> methods.
1640
1683
 
1641
- If the default modification methods would not do what you want, and you
1642
- don't plan on overriding the internal modification methods to do what you
1643
- want, it may be best to set this option to true.
1684
+ If you are not using the association modification methods, setting this
1685
+ value to true will save memory.
1644
1686
 
1645
1687
  ==== :validate
1646
1688
 
@@ -1667,12 +1709,35 @@ If set to false, you cannot load the association eagerly via eager or
1667
1709
  eager_graph.
1668
1710
 
1669
1711
  Artist.one_to_many :albums, allow_eager: false
1670
- Artist.eager(:albums) # Raises Sequel::Error
1712
+ Artist.eager(:albums) # Raises Sequel::Error
1713
+ Artist.eager_graph(:albums) # Raises Sequel::Error
1671
1714
 
1672
1715
  This is usually used if the association dataset depends on specific values in
1673
1716
  model instance that would not be valid when eager loading for multiple
1674
1717
  instances.
1675
1718
 
1719
+ ==== :allow_eager_graph
1720
+
1721
+ If set to false, you cannot load the association eagerly via eager_graph.
1722
+
1723
+ Artist.one_to_many :albums, allow_eager_graph: false
1724
+ Artist.eager(:albums) # Allowed
1725
+ Artist.eager_graph(:albums) # Raises Sequel::Error
1726
+
1727
+ This is useful if you still want to allow loading via eager, but do not want
1728
+ to allow loading via eager graph, possibly because the association does not
1729
+ support joins.
1730
+
1731
+ ==== :allow_filtering_by
1732
+
1733
+ If set to false, you cannot use the association when filtering.
1734
+
1735
+ Artist.one_to_many :albums, allow_filtering_by: false
1736
+ Artist.where(albums: Album.where(name: 'A')).all # Raises Sequel::Error
1737
+
1738
+ This is useful if such filtering cannot work, such as when a subquery cannot
1739
+ be used because the necessary tables are not in the same database.
1740
+
1676
1741
  ==== :instance_specific
1677
1742
 
1678
1743
  This allows you to override the setting of whether the dataset contains instance
data/doc/cheat_sheet.rdoc CHANGED
@@ -54,8 +54,16 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
54
54
  == Update/Delete rows
55
55
 
56
56
  dataset.exclude(:active).delete
57
- dataset.where{price < 100}.update(:active => true)
58
- dataset.where(:active).update(:price => Sequel[:price] * 0.90)
57
+ dataset.where{price < 100}.update(active: true)
58
+ dataset.where(:active).update(price: Sequel[:price] * 0.90)
59
+
60
+ = Merge rows
61
+
62
+ dataset.
63
+ merge_using(:table, col1: :col2).
64
+ merge_insert(col3: :col4).
65
+ merge_delete{col5 > 30}.
66
+ merge_update(col3: Sequel[:col3] + :col4)
59
67
 
60
68
  == Datasets are Enumerable
61
69
 
@@ -166,7 +174,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
166
174
  String :name, unique: true, null: false
167
175
  TrueClass :active, default: true
168
176
  foreign_key :category_id, :categories
169
- DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, :index=>true
177
+ DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, index: true
170
178
 
171
179
  index [:category_id, :active]
172
180
  end
data/doc/migration.rdoc CHANGED
@@ -352,7 +352,7 @@ you should give it some thought before using it.
352
352
 
353
353
  == Ignoring missing migrations
354
354
 
355
- In some cases, you may want to allow a migration in the database that does not exist in the filesystem (deploying to an older version of code without running a down migration when deploy auto-migrates, for example). If required, you can pass <tt>allow_missing_migration_files: true</tt> as an option. This will stop errors from being raised if there are migrations in the database that do not exist in the filesystem.
355
+ In some cases, you may want to allow a migration in the database that does not exist in the filesystem (deploying to an older version of code without running a down migration when deploy auto-migrates, for example). If required, you can pass <tt>allow_missing_migration_files: true</tt> as an option. This will stop errors from being raised if there are migrations in the database that do not exist in the filesystem. Note that the migrations themselves can still raise an error when using this option, if the database schema isn't in the state the migrations expect it to be in. In general, the <tt>allow_missing_migration_files: true</tt> option is very risky to use, and should only be used if it is absolutely necessary.
356
356
 
357
357
  == Modifying existing migrations
358
358
 
@@ -543,16 +543,22 @@ The main difference between the two is that <tt>-d</tt> will use the type method
543
543
  with the database independent ruby class types, while <tt>-D</tt> will use
544
544
  the +column+ method with string types.
545
545
 
546
- Note that Sequel cannot dump constraints other than primary key and possibly
547
- foreign key constraints. If you are using database features such
548
- as constraints or triggers, you should use your database's dump and restore
549
- programs instead of Sequel's schema dumper.
550
-
551
546
  You can take the migration created by the schema dumper to another computer
552
547
  with an empty database, and attempt to recreate the schema using:
553
548
 
554
549
  sequel -m db/migrations postgres://host/database
555
550
 
551
+ The schema_dumper extension is quite limited in what types of
552
+ database objects it supports. In general, it only supports
553
+ dumping tables, columns, primary key and foreign key constraints,
554
+ and some indexes. It does not support most table options, CHECK
555
+ constraints, partial indexes, database functions, triggers,
556
+ security grants/revokes, and a wide variety of other useful
557
+ database properties. Be aware of the limitations when using the
558
+ schema_dumper extension. If you are dumping the schema to restore
559
+ to the same database type, it is recommended to use your database's
560
+ dump and restore programs instead of the schema_dumper extension.
561
+
556
562
  == Checking for Current Migrations
557
563
 
558
564
  In your application code, you may want to check that you are up to date in
data/doc/model_hooks.rdoc CHANGED
@@ -199,7 +199,7 @@ While it's not enforced anywhere, it's a good idea to make +super+ the last expr
199
199
 
200
200
  def after_save
201
201
  super
202
- AuditLog.create(:log=>"Album #{name} created")
202
+ AuditLog.create(log: "Album #{name} created")
203
203
  end
204
204
  end
205
205
 
@@ -36,7 +36,7 @@ schema modification,
36
36
  and transactions:
37
37
 
38
38
  DB.transaction do
39
- DB[:table].insert(:column=>value)
39
+ DB[:table].insert(column: value)
40
40
  end
41
41
 
42
42
  Sequel::Database#literal can be used to take any object that Sequel handles
@@ -468,7 +468,7 @@ objects:
468
468
  Sequel.lit(['', ' = '], :a, 1)
469
469
 
470
470
  '? = ?'.lit(:a, 1) # core_extensions extension
471
- ':b = :v'.lit(:b=>:a, :v=>1) # core_extensions extension
471
+ ':b = :v'.lit(b: :a, v: 1) # core_extensions extension
472
472
 
473
473
  === Sequel::SQL::OrderedExpression
474
474
 
@@ -482,20 +482,20 @@ it ascending or descending:
482
482
  Additionally, they take an options hash, which can be used to specify how nulls
483
483
  can be sorted:
484
484
 
485
- Sequel::SQL::OrderedExpression.new(:a, true, :nulls=>:first) # "a" DESC NULLS FIRST
486
- Sequel::SQL::OrderedExpression.new(:a, false, :nulls=>:last) # "a" ASC NULLS LAST
485
+ Sequel::SQL::OrderedExpression.new(:a, true, nulls: :first) # "a" DESC NULLS FIRST
486
+ Sequel::SQL::OrderedExpression.new(:a, false, nulls: :last) # "a" ASC NULLS LAST
487
487
 
488
488
  The following shortcuts exist for creating Sequel::SQL::OrderedExpression objects:
489
489
 
490
490
  Sequel.asc(:a)
491
491
  Sequel.desc(:a)
492
- Sequel.asc(:a, :nulls=>:first)
493
- Sequel.desc(:a, :nulls=>:last)
492
+ Sequel.asc(:a, nulls: :first)
493
+ Sequel.desc(:a, nulls: :last)
494
494
 
495
495
  :a.asc # core_extensions extension
496
496
  :a.desc # core_extensions extension
497
- :a.asc(:nulls=>:first) # core_extensions extension
498
- :a.desc(:nulls=>:last) # core_extensions extension
497
+ :a.asc(nulls: :first) # core_extensions extension
498
+ :a.desc(nulls: :last) # core_extensions extension
499
499
 
500
500
  === Sequel::SQL::Subscript
501
501
 
@@ -102,6 +102,7 @@ The following options can be specified and are passed to the database's internal
102
102
  :after_connect :: A callable object called after each new connection is made, with the
103
103
  connection object (and server argument if the callable accepts 2 arguments),
104
104
  useful for customizations that you want to apply to all connections (nil by default).
105
+ :connect_sqls :: An array of sql strings to execute on each new connection, after :after_connect runs.
105
106
  :max_connections :: The maximum size of the connection pool (4 connections by default on most databases)
106
107
  :pool_timeout :: The number of seconds to wait if a connection cannot be acquired before raising an error (5 seconds by default)
107
108
  :single_threaded :: Whether to use a single-threaded (non-thread safe) connection pool
@@ -249,7 +250,7 @@ jdbc-mysql :: Depending on the configuration of the MySQL server, jdbc-mysql ver
249
250
 
250
251
  Requires: mysql
251
252
 
252
- The MySQL adapter does not support the pure-ruby mysql.rb driver, it requires the C-extension driver.
253
+ This should work with the mysql gem (C extension) and the ruby-mysql gem (pure ruby).
253
254
 
254
255
  The following additional options are supported:
255
256
 
@@ -258,6 +259,8 @@ The following additional options are supported:
258
259
  :compress :: Whether to compress data sent/received via the socket connection.
259
260
  :config_default_group :: The default group to read from the in the MySQL config file, defaults to "client")
260
261
  :config_local_infile :: If provided, sets the Mysql::OPT_LOCAL_INFILE option on the connection with the given value.
262
+ :disable_split_materialized :: Set split_materialized=off in the optimizer settings. Necessary to pass the associations
263
+ integration tests in MariaDB 10.5+, due to a unfixed bug in the optimizer.
261
264
  :encoding :: Specify the encoding/character set to use for the connection.
262
265
  :fractional_seconds :: On MySQL 5.6.5+, this option is recognized and will include fractional seconds in
263
266
  time/timestamp values, as well as have the schema method create columns that can contain
@@ -265,7 +268,7 @@ The following additional options are supported:
265
268
  to MySQL.
266
269
  :socket :: Can be used to specify a Unix socket file to connect to instead of a TCP host and port.
267
270
  :sql_mode :: Set the sql_mode(s) for a given connection. Can be single symbol or string,
268
- or an array of symbols or strings (e.g. <tt>:sql_mode=>[:no_zero_date, :pipes_as_concat]</tt>).
271
+ or an array of symbols or strings (e.g. <tt>sql_mode: [:no_zero_date, :pipes_as_concat]</tt>).
269
272
  :timeout :: Sets the wait_timeout for the connection, defaults to 1 month.
270
273
  :read_timeout :: Set the timeout in seconds for reading back results to a query.
271
274
  :connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned
@@ -278,20 +281,22 @@ if either the :sslca or :sslkey option is given.
278
281
 
279
282
  This is a newer MySQL adapter that does typecasting in C, so it is often faster than the
280
283
  mysql adapter. The options given are passed to Mysql2::Client.new, see the mysql2 documentation
281
- for details on what options are supported.
284
+ for details on what options are supported. The :timeout, :auto_is_null, :sql_mode, and :disable_split_materialized
285
+ options supported by the mysql adapter are also supported for mysql2 adapter (and any other adapters connecting to
286
+ mysql, such as the jdbc/mysql adapter).
282
287
 
283
288
  === odbc
284
289
 
285
290
  The ODBC adapter allows you to connect to any database with the appropriate ODBC drivers installed.
286
291
  The :database option given ODBC database should be the DSN (Descriptive Service Name) from the ODBC configuration.
287
292
 
288
- Sequel.odbc('mydb', :user => "user", :password => "password")
293
+ Sequel.odbc('mydb', user: "user", password: "password")
289
294
 
290
295
  The :host and :port options are not respected. The following additional options are supported:
291
296
 
292
297
  :db_type :: Can be specified as 'mssql', 'progress', or 'db2' to use SQL syntax specific to those databases.
293
298
  :drvconnect :: Can be given an ODBC connection string, and will use ODBC::Database#drvconnect to
294
- do the connection. Typical usage would be: <tt>Sequel.odbc(:drvconnect=>'driver={...};...')</tt>
299
+ do the connection. Typical usage would be: <tt>Sequel.odbc(drvconnect: 'driver={...};...')</tt>
295
300
 
296
301
  === oracle
297
302
 
@@ -307,15 +312,14 @@ The following additional options are supported:
307
312
 
308
313
  === postgres
309
314
 
310
- Requires: pg (or postgres-pr/postgres-compat if pg is not available)
315
+ Requires: pg (or sequel/postgres-pr or postgres-pr/postgres-compat if pg is not available)
311
316
 
312
- The Sequel postgres adapter works with the pg and postgres-pr ruby libraries.
317
+ The Sequel postgres adapter works with the pg, sequel-postgres-pr, jeremyevans-postgres-pr, and postgres-pr ruby libraries.
313
318
  The pg library is the best supported, as it supports real bound variables and prepared statements.
314
319
  If the pg library is being used, Sequel will also attempt to load the sequel_pg library, which is
315
320
  a C extension that optimizes performance when Sequel is used with pg. All users of Sequel who
316
- use pg are encouraged to install sequel_pg. For users who want to use postgres-pr to avoid issues
317
- with C extensions, it is recommended to use jeremyevans-postgres-pr, which fixes many issues in
318
- the upstream postgres-pr gem, and is regularly tested with Sequel.
321
+ use pg are encouraged to install sequel_pg. For users who want to use one of the postgres-pr
322
+ libraries to avoid issues with C extensions, it is recommended to use sequel-postgres-pr.
319
323
 
320
324
  The following additional options are supported:
321
325
 
@@ -341,7 +345,7 @@ The following additional options are supported:
341
345
  :search_path :: Set to the schema search_path. This can either be a single string containing the schemas
342
346
  separated by commas (for use via a URL: <tt>postgres:///?search_path=schema1,schema2</tt>), or it
343
347
  can be an array of strings (for use via an option:
344
- <tt>Sequel.postgres(:search_path=>['schema1', 'schema2'])</tt>).
348
+ <tt>Sequel.postgres(search_path: ['schema1', 'schema2'])</tt>).
345
349
  :use_iso_date_format :: This can be set to false to not force the ISO date format. Sequel forces
346
350
  it by default to allow for an optimization.
347
351
 
@@ -383,6 +387,9 @@ The following additional options are supported:
383
387
 
384
388
  :readonly :: open database in read-only mode
385
389
  :timeout :: the busy timeout to use in milliseconds (default: 5000).
390
+ :setup_regexp_function :: Whether to setup a REGEXP function in the underlying SQLite3::Database object. Doing so
391
+ allows you to use regexp support in dataset expressions. Note that this creates a new
392
+ Regexp object per call to the function, so it is not an efficient implementation.
386
393
 
387
394
  Note that SQLite memory databases are restricted to a single connection by
388
395
  default. This is because SQLite does not allow multiple connections to
data/doc/postgresql.rdoc CHANGED
@@ -295,16 +295,16 @@ option to +foreign_key_list+:
295
295
  primary_key :id
296
296
  Integer :i
297
297
  Integer :j
298
- foreign_key :a_id, :a, :foreign_key_constraint_name=>:a_a
298
+ foreign_key :a_id, :a, foreign_key_constraint_name: :a_a
299
299
  unique [:i, :j]
300
300
  end
301
301
  DB.create_table!(:b) do
302
- foreign_key :a_id, :a, :foreign_key_constraint_name=>:a_a
302
+ foreign_key :a_id, :a, foreign_key_constraint_name: :a_a
303
303
  Integer :c
304
304
  Integer :d
305
- foreign_key [:c, :d], :a, :key=>[:j, :i], :name=>:a_c_d
305
+ foreign_key [:c, :d], :a, key: [:j, :i], name: :a_c_d
306
306
  end
307
- DB.foreign_key_list(:a, :reverse=>true)
307
+ DB.foreign_key_list(:a, reverse: true)
308
308
  # => [
309
309
  # {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:a, :schema=>:public},
310
310
  # {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:b, :schema=>:public},
@@ -413,12 +413,12 @@ syntax:
413
413
 
414
414
  DB.create_table(:table){primary_key :id}
415
415
  # Ignore the given value for id, using the identity's sequence value.
416
- DB[:table].overriding_user_value.insert(:id=>1)
416
+ DB[:table].overriding_user_value.insert(id: 1)
417
417
 
418
- DB.create_table(:table){primary_key :id, :identity=>:always}
418
+ DB.create_table(:table){primary_key :id, identity: :always}
419
419
  # Force the use of the given value for id, because otherwise the insert will
420
420
  # raise an error, since GENERATED ALWAYS was used when creating the column.
421
- DB[:table].overriding_system_value.insert(:id=>1)
421
+ DB[:table].overriding_system_value.insert(id: 1)
422
422
 
423
423
  === Distinct On Specific Columns
424
424
 
@@ -428,6 +428,14 @@ rows that are distinct on just those columns:
428
428
  DB[:table].distinct(:id).all
429
429
  # SELECT DISTINCT ON ("id") * FROM "table"
430
430
 
431
+ === JOIN USING table alias
432
+
433
+ Sequel allows passing an SQL::AliasedExpression to join table methods to use a USING
434
+ join with a table alias for the USING columns:
435
+
436
+ DB[:t1].join(:t2, Sequel.as([:c1, :c2], :alias))
437
+ # SELECT * FROM "t1" INNER JOIN "t2" USING ("c1", "c2") AS "alias"
438
+
431
439
  === Calling PostgreSQL 11+ Procedures <tt>postgres only</tt>
432
440
 
433
441
  PostgreSQL 11+ added support for procedures, which are different from the user defined
@@ -553,7 +561,7 @@ such as the related table and column or constraint.
553
561
 
554
562
  DB.create_table(:test1){primary_key :id}
555
563
  DB.create_table(:test2){primary_key :id; foreign_key :test1_id, :test1}
556
- DB[:test2].insert(:test1_id=>1) rescue DB.error_info($!)
564
+ DB[:test2].insert(test1_id: 1) rescue DB.error_info($!)
557
565
  # => {
558
566
  # :schema=>"public",
559
567
  # :table=>"test2",
data/doc/querying.rdoc CHANGED
@@ -357,7 +357,9 @@ For ranges, Sequel uses a pair of inequality statements:
357
357
  # SELECT * FROM artists WHERE ((id >= 1) AND (id < 5))
358
358
 
359
359
  Finally, for regexps, Sequel uses an SQL regular expression. Note that this
360
- is probably only supported on PostgreSQL and MySQL.
360
+ is only supported by default on PostgreSQL and MySQL. It can also be supported
361
+ on SQLite when using the sqlite adapter with the :setup_regexp_function
362
+ Database option.
361
363
 
362
364
  Artist.where(name: /JM$/)
363
365
  # SELECT * FROM artists WHERE (name ~ 'JM$')
@@ -498,7 +500,7 @@ filters:
498
500
  # SELECT * FROM artists WHERE (id != 5)
499
501
 
500
502
  Artist.where(id: 5).exclude{name > 'A'}
501
- # SELECT * FROM artists WHERE ((id = 5) OR (name <= 'A')
503
+ # SELECT * FROM artists WHERE ((id = 5) AND (name <= 'A')
502
504
 
503
505
  So to do a NOT IN with an array:
504
506
 
@@ -713,7 +715,7 @@ aggregation:
713
715
 
714
716
  Album.select_group(:artist_id).select_append{sum(num_tracks).as(tracks)}
715
717
  # SELECT artist_id, sum(num_tracks) AS tracks FROM albums GROUP BY artist_id
716
-
718
+
717
719
  == Having
718
720
 
719
721
  The SQL HAVING clause is similar to the WHERE clause, except that
@@ -0,0 +1,40 @@
1
+ = New Features
2
+
3
+ * On SQLite 3.33.0+, the UPDATE FROM syntax is now supported. This
4
+ allows you to update one table based on a join to another table.
5
+ The SQLite syntax is based on the PostgreSQL syntax, and the
6
+ Sequel API is the same for both. You need to pass multiple tables
7
+ to Dataset#from. The first table is the table to update, and the
8
+ remaining tables are used to construct the UPDATE FROM clause:
9
+
10
+ DB[:a, :b].where{{a[:c]=>b[:d]}}.update(:e=>'f')
11
+ # UPDATE a SET e = 'f' FROM b WHERE (a.c = b.d)
12
+
13
+ Unlike PostgreSQL, SQLite does not support the deletion of joined
14
+ datasets. Related to this, the following methods for testing
15
+ database support for modifying joined datasets have been added:
16
+
17
+ * supports_updating_joins?
18
+ * supports_deleting_joins?
19
+
20
+ = Other Improvements
21
+
22
+ * The pg_interval and date_arithmetic extensions now support
23
+ ActiveSupport 6.1.
24
+
25
+ * Sequel no longer issues method redefinition warnings in verbose
26
+ mode. As Ruby 3 has dropped uninitialized instance variable
27
+ warnings, Sequel is now verbose warning free on Ruby 3.
28
+
29
+ = Backwards Compatibility
30
+
31
+ * Trying to truncate or insert into a joined dataset now correctly
32
+ raises an exception even if the joined dataset supports updates.
33
+
34
+ * The private Dataset#check_modification_allowed! method is now
35
+ deprecated, and users (custom adapters) should now switch to one
36
+ of the more specific methods introduced in this version:
37
+
38
+ * check_insert_allowed!
39
+ * check_update_allowed!
40
+ * check_delete_allowed!
@@ -0,0 +1,25 @@
1
+ = New Features
2
+
3
+ * The validation methods added by the validation_helpers plugin now
4
+ support the :skip_invalid option, which will not add a validation
5
+ error on a column if it already has a validation error. This can
6
+ be useful if you want to avoid having duplicate errors.
7
+
8
+ * The auto_validations plugin now supports a :skip_invalid plugin
9
+ option, which will pass the :skip_invalid option when calling
10
+ validation methods.
11
+
12
+ = Other Improvements
13
+
14
+ * The :adder, :remover, and :clearer association options now
15
+ support keyword arguments in Ruby 2.7+.
16
+
17
+ * In the pg_interval extension, Sequel now uses the same number of
18
+ seconds per month and seconds per year as active_support. It
19
+ originally used the same number, but active_support changed the
20
+ values in active_support 5.1. Sequel now uses the active_support
21
+ values if they are available.
22
+
23
+ * When adding a String column on PostgreSQL, an explicit text: true
24
+ option now takes precedence over an explicit :size option, as it
25
+ does in Sequel's default behavior.