sequel 5.60.1 → 5.81.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +280 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +27 -24
  5. data/doc/advanced_associations.rdoc +16 -14
  6. data/doc/association_basics.rdoc +53 -17
  7. data/doc/cheat_sheet.rdoc +3 -3
  8. data/doc/code_order.rdoc +5 -3
  9. data/doc/dataset_basics.rdoc +1 -1
  10. data/doc/mass_assignment.rdoc +1 -1
  11. data/doc/migration.rdoc +15 -0
  12. data/doc/model_hooks.rdoc +1 -1
  13. data/doc/object_model.rdoc +8 -8
  14. data/doc/opening_databases.rdoc +18 -7
  15. data/doc/postgresql.rdoc +8 -8
  16. data/doc/querying.rdoc +7 -2
  17. data/doc/release_notes/5.61.0.txt +43 -0
  18. data/doc/release_notes/5.62.0.txt +132 -0
  19. data/doc/release_notes/5.63.0.txt +33 -0
  20. data/doc/release_notes/5.64.0.txt +50 -0
  21. data/doc/release_notes/5.65.0.txt +21 -0
  22. data/doc/release_notes/5.66.0.txt +24 -0
  23. data/doc/release_notes/5.67.0.txt +32 -0
  24. data/doc/release_notes/5.68.0.txt +61 -0
  25. data/doc/release_notes/5.69.0.txt +26 -0
  26. data/doc/release_notes/5.70.0.txt +35 -0
  27. data/doc/release_notes/5.71.0.txt +21 -0
  28. data/doc/release_notes/5.72.0.txt +33 -0
  29. data/doc/release_notes/5.73.0.txt +66 -0
  30. data/doc/release_notes/5.74.0.txt +45 -0
  31. data/doc/release_notes/5.75.0.txt +35 -0
  32. data/doc/release_notes/5.76.0.txt +86 -0
  33. data/doc/release_notes/5.77.0.txt +63 -0
  34. data/doc/release_notes/5.78.0.txt +67 -0
  35. data/doc/release_notes/5.79.0.txt +28 -0
  36. data/doc/release_notes/5.80.0.txt +40 -0
  37. data/doc/release_notes/5.81.0.txt +31 -0
  38. data/doc/schema_modification.rdoc +3 -3
  39. data/doc/security.rdoc +9 -9
  40. data/doc/sharding.rdoc +3 -1
  41. data/doc/sql.rdoc +14 -14
  42. data/doc/testing.rdoc +16 -12
  43. data/doc/transactions.rdoc +6 -6
  44. data/doc/virtual_rows.rdoc +1 -1
  45. data/lib/sequel/adapters/ibmdb.rb +1 -1
  46. data/lib/sequel/adapters/jdbc/h2.rb +3 -0
  47. data/lib/sequel/adapters/jdbc/hsqldb.rb +2 -0
  48. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -0
  49. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +15 -0
  50. data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -0
  51. data/lib/sequel/adapters/jdbc.rb +10 -6
  52. data/lib/sequel/adapters/mysql.rb +19 -7
  53. data/lib/sequel/adapters/mysql2.rb +2 -2
  54. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  55. data/lib/sequel/adapters/oracle.rb +1 -0
  56. data/lib/sequel/adapters/postgres.rb +10 -5
  57. data/lib/sequel/adapters/shared/access.rb +9 -1
  58. data/lib/sequel/adapters/shared/db2.rb +12 -0
  59. data/lib/sequel/adapters/shared/mssql.rb +71 -9
  60. data/lib/sequel/adapters/shared/mysql.rb +82 -3
  61. data/lib/sequel/adapters/shared/oracle.rb +17 -7
  62. data/lib/sequel/adapters/shared/postgres.rb +469 -160
  63. data/lib/sequel/adapters/shared/sqlanywhere.rb +18 -5
  64. data/lib/sequel/adapters/shared/sqlite.rb +39 -3
  65. data/lib/sequel/adapters/sqlite.rb +42 -3
  66. data/lib/sequel/adapters/trilogy.rb +117 -0
  67. data/lib/sequel/connection_pool/sharded_threaded.rb +16 -11
  68. data/lib/sequel/connection_pool/sharded_timed_queue.rb +374 -0
  69. data/lib/sequel/connection_pool/threaded.rb +14 -8
  70. data/lib/sequel/connection_pool/timed_queue.rb +270 -0
  71. data/lib/sequel/connection_pool.rb +57 -31
  72. data/lib/sequel/database/connecting.rb +25 -1
  73. data/lib/sequel/database/dataset.rb +16 -6
  74. data/lib/sequel/database/misc.rb +65 -14
  75. data/lib/sequel/database/query.rb +72 -1
  76. data/lib/sequel/database/schema_generator.rb +1 -1
  77. data/lib/sequel/database/schema_methods.rb +12 -5
  78. data/lib/sequel/database/transactions.rb +6 -0
  79. data/lib/sequel/dataset/actions.rb +60 -13
  80. data/lib/sequel/dataset/dataset_module.rb +1 -1
  81. data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +42 -0
  82. data/lib/sequel/dataset/features.rb +15 -1
  83. data/lib/sequel/dataset/graph.rb +1 -0
  84. data/lib/sequel/dataset/misc.rb +12 -2
  85. data/lib/sequel/dataset/placeholder_literalizer.rb +20 -9
  86. data/lib/sequel/dataset/query.rb +119 -45
  87. data/lib/sequel/dataset/sql.rb +58 -36
  88. data/lib/sequel/dataset.rb +4 -0
  89. data/lib/sequel/exceptions.rb +5 -0
  90. data/lib/sequel/extensions/_model_pg_row.rb +0 -12
  91. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  92. data/lib/sequel/extensions/any_not_empty.rb +2 -2
  93. data/lib/sequel/extensions/async_thread_pool.rb +21 -13
  94. data/lib/sequel/extensions/auto_cast_date_and_time.rb +94 -0
  95. data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
  96. data/lib/sequel/extensions/caller_logging.rb +4 -1
  97. data/lib/sequel/extensions/connection_expiration.rb +15 -9
  98. data/lib/sequel/extensions/connection_validator.rb +16 -11
  99. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  100. data/lib/sequel/extensions/date_arithmetic.rb +1 -1
  101. data/lib/sequel/extensions/duplicate_columns_handler.rb +10 -9
  102. data/lib/sequel/extensions/index_caching.rb +5 -1
  103. data/lib/sequel/extensions/looser_typecasting.rb +3 -0
  104. data/lib/sequel/extensions/migration.rb +65 -15
  105. data/lib/sequel/extensions/named_timezones.rb +22 -6
  106. data/lib/sequel/extensions/pg_array.rb +33 -4
  107. data/lib/sequel/extensions/pg_auto_parameterize.rb +509 -0
  108. data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +110 -0
  109. data/lib/sequel/extensions/pg_enum.rb +1 -2
  110. data/lib/sequel/extensions/pg_extended_date_support.rb +38 -27
  111. data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
  112. data/lib/sequel/extensions/pg_hstore.rb +5 -0
  113. data/lib/sequel/extensions/pg_inet.rb +10 -11
  114. data/lib/sequel/extensions/pg_interval.rb +10 -11
  115. data/lib/sequel/extensions/pg_json.rb +10 -10
  116. data/lib/sequel/extensions/pg_json_ops.rb +3 -3
  117. data/lib/sequel/extensions/pg_multirange.rb +6 -11
  118. data/lib/sequel/extensions/pg_range.rb +9 -14
  119. data/lib/sequel/extensions/pg_row.rb +20 -19
  120. data/lib/sequel/extensions/pg_timestamptz.rb +27 -3
  121. data/lib/sequel/extensions/provenance.rb +110 -0
  122. data/lib/sequel/extensions/round_timestamps.rb +1 -1
  123. data/lib/sequel/extensions/schema_caching.rb +1 -1
  124. data/lib/sequel/extensions/schema_dumper.rb +32 -9
  125. data/lib/sequel/extensions/server_block.rb +2 -1
  126. data/lib/sequel/extensions/set_literalizer.rb +58 -0
  127. data/lib/sequel/extensions/sqlite_json_ops.rb +76 -18
  128. data/lib/sequel/extensions/temporarily_release_connection.rb +178 -0
  129. data/lib/sequel/extensions/transaction_connection_validator.rb +78 -0
  130. data/lib/sequel/model/associations.rb +38 -11
  131. data/lib/sequel/model/base.rb +32 -18
  132. data/lib/sequel/model/dataset_module.rb +3 -0
  133. data/lib/sequel/model/exceptions.rb +15 -3
  134. data/lib/sequel/plugins/auto_validations.rb +53 -15
  135. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  136. data/lib/sequel/plugins/column_encryption.rb +28 -7
  137. data/lib/sequel/plugins/composition.rb +2 -2
  138. data/lib/sequel/plugins/concurrent_eager_loading.rb +4 -4
  139. data/lib/sequel/plugins/constraint_validations.rb +8 -5
  140. data/lib/sequel/plugins/defaults_setter.rb +16 -0
  141. data/lib/sequel/plugins/dirty.rb +1 -1
  142. data/lib/sequel/plugins/finder.rb +4 -2
  143. data/lib/sequel/plugins/input_transformer.rb +1 -1
  144. data/lib/sequel/plugins/list.rb +5 -2
  145. data/lib/sequel/plugins/many_through_many.rb +1 -1
  146. data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -38
  147. data/lib/sequel/plugins/nested_attributes.rb +4 -4
  148. data/lib/sequel/plugins/optimistic_locking.rb +9 -42
  149. data/lib/sequel/plugins/optimistic_locking_base.rb +55 -0
  150. data/lib/sequel/plugins/paged_operations.rb +181 -0
  151. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +9 -3
  152. data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +109 -0
  153. data/lib/sequel/plugins/prepared_statements.rb +2 -1
  154. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -1
  155. data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
  156. data/lib/sequel/plugins/rcte_tree.rb +7 -4
  157. data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
  158. data/lib/sequel/plugins/sql_comments.rb +1 -1
  159. data/lib/sequel/plugins/static_cache.rb +38 -0
  160. data/lib/sequel/plugins/static_cache_cache.rb +5 -1
  161. data/lib/sequel/plugins/tactical_eager_loading.rb +14 -14
  162. data/lib/sequel/plugins/validate_associated.rb +22 -12
  163. data/lib/sequel/plugins/validation_helpers.rb +29 -2
  164. data/lib/sequel/plugins/validation_helpers_generic_type_messages.rb +73 -0
  165. data/lib/sequel/version.rb +2 -2
  166. metadata +79 -6
@@ -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,6 +342,12 @@ 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
353
  In addition to the above methods, associations also add an instance method
@@ -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+]
@@ -858,14 +864,14 @@ You can set this to +nil+ to not create a remove_all_<i>association</i> method.
858
864
 
859
865
  === :no_dataset_method
860
866
 
861
- Setting this to true will not result in the <i>association</i>_dataset method
867
+ Setting this to true will result in the <i>association</i>_dataset method
862
868
  not being defined. This can save memory if you only use the <i>association</i>
863
869
  method and do not call the <i>association</i>_dataset method directly or
864
870
  indirectly.
865
871
 
866
872
  === :no_association_method
867
873
 
868
- Setting this to true will not result in the <i>association</i> method
874
+ Setting this to true will result in the <i>association</i> method
869
875
  not being defined. This can save memory if you only use the
870
876
  <i>association</i>_dataset method and do not call the <i>association</i> method
871
877
  directly or indirectly.
@@ -981,7 +987,7 @@ If you do not use a hash or array of two element arrays, you should use the
981
987
  :graph_conditions, :graph_only_conditions, or :graph_block option or you will not
982
988
  be able to use eager_graph or association_join with the association.
983
989
 
984
- Artist.one_to_many :good_albums, class: :Album, conditions: {:good=>true}
990
+ Artist.one_to_many :good_albums, class: :Album, conditions: {good: true}
985
991
  @artist.good_albums
986
992
  # SELECT * FROM albums WHERE ((artist_id = 1) AND (good IS TRUE))
987
993
 
@@ -1162,7 +1168,7 @@ join of the join table and the associated table, whereas this option just
1162
1168
  applies to the join table. It can be used to make sure that filters are used
1163
1169
  when deleting.
1164
1170
 
1165
- 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|
1166
1172
  ds.where(instrument_id: 5)
1167
1173
  end)
1168
1174
 
@@ -1177,7 +1183,7 @@ access to the join table.
1177
1183
  For example, if the Album class uses a different Sequel::Database than the Artist
1178
1184
  class, and the join table is in the database that the Artist class uses:
1179
1185
 
1180
- Artist.many_to_many :lead_guitar_albums, class: :Album, :join_table_db=>Artist.db
1186
+ Artist.many_to_many :lead_guitar_albums, class: :Album, join_table_db: Artist.db
1181
1187
 
1182
1188
  This option also affects the add/remove/remove_all methods, by changing
1183
1189
  which database is used for inserts/deletes from the join table (add/remove/remove_all
@@ -1470,7 +1476,7 @@ at least the following keys:
1470
1476
  Example:
1471
1477
 
1472
1478
  Artist.one_to_many :self_title_albums, class: :Album,
1473
- :eager_grapher=>(lambda do |eo|
1479
+ eager_grapher: (lambda do |eo|
1474
1480
  eo[:self].graph(:albums, {artist_id: :id, name: :name},
1475
1481
  table_alias: eo[:table_alias], implicit_qualifier: eo[:implicit_qualifier])
1476
1482
  end)
@@ -1492,6 +1498,36 @@ as the qualifiers may not match the aliases automatically used by eager_graph.
1492
1498
  This should contain unqualified identifiers, and eager_graph will automatically
1493
1499
  qualify them with the appropriate alias.
1494
1500
 
1501
+ ==== :graph_use_association_block
1502
+
1503
+ Setting this to true makes eager_graph apply the association block to the
1504
+ associated dataset before graphing the associated dataset into the receiver.
1505
+ In most cases when this option is used and the association has a block, the
1506
+ dataset returned by eager_graph will contain a JOIN to a subquery.
1507
+
1508
+ By default (when this option is not used), the association block will be ignored
1509
+ when using eager_graph:
1510
+
1511
+ Artist.one_to_many :tracks do |ds|
1512
+ ds.where(foo: 3)
1513
+ end
1514
+ Artist.eager_graph(:tracks)
1515
+ # SELECT albums.id, tracks.id AS tracks_id, tracks.album_id
1516
+ # FROM albums
1517
+ # LEFT OUTER JOIN tracks
1518
+ # ON (tracks.album_id = albums.id)
1519
+
1520
+ When this option is used, the block will be respected:
1521
+
1522
+ Artist.one_to_many :tracks, graph_use_association_block: true do |ds|
1523
+ ds.where(foo: 3)
1524
+ end
1525
+ Artist.eager_graph(:tracks)
1526
+ # SELECT albums.id, tracks.id AS tracks_id, tracks.album_id
1527
+ # FROM albums
1528
+ # LEFT OUTER JOIN (SELECT * FROM tracks WHERE (foo = 3)) AS tracks
1529
+ # ON (tracks.album_id = albums.id)
1530
+
1495
1531
  ==== :graph_join_table_conditions [+many_to_many+, +one_through_one+]
1496
1532
 
1497
1533
  The additional conditions to use on the SQL join for the join table when
@@ -1727,7 +1763,7 @@ support joins.
1727
1763
  If set to false, you cannot use the association when filtering.
1728
1764
 
1729
1765
  Artist.one_to_many :albums, allow_filtering_by: false
1730
- Artist.where(:albums=>Album.where(:name=>'A')).all # Raises Sequel::Error
1766
+ Artist.where(albums: Album.where(name: 'A')).all # Raises Sequel::Error
1731
1767
 
1732
1768
  This is useful if such filtering cannot work, such as when a subquery cannot
1733
1769
  be used because the necessary tables are not in the same database.
data/doc/cheat_sheet.rdoc CHANGED
@@ -54,8 +54,8 @@ 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
59
 
60
60
  = Merge rows
61
61
 
@@ -174,7 +174,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
174
174
  String :name, unique: true, null: false
175
175
  TrueClass :active, default: true
176
176
  foreign_key :category_id, :categories
177
- DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, :index=>true
177
+ DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, index: true
178
178
 
179
179
  index [:category_id, :active]
180
180
  end
data/doc/code_order.rdoc CHANGED
@@ -91,9 +91,11 @@ unsafe runtime modification of the configuration:
91
91
  model_classes.each(&:freeze)
92
92
  DB.freeze
93
93
 
94
- The `subclasses` plugin can be used to keep track of all model classes
95
- that have been setup in your application. Finalizing their associations
96
- and freezing them can easily be achieved through the plugin:
94
+ `model_classes` is not a Sequel method, it indicates an array of model
95
+ classes you defined. Instead of listing them manually, the `subclasses`
96
+ plugin can be used to keep track of all model classes that have been
97
+ setup in your application. Finalizing their associations and freezing
98
+ them can easily be achieved through the plugin:
97
99
 
98
100
  # Register the plugin before setting up the models
99
101
  Sequel::Model.plugin :subclasses
@@ -65,7 +65,7 @@ Most Dataset methods that users will use can be broken down into two types:
65
65
 
66
66
  Most dataset methods fall into this category, which can be further broken down by the clause they affect:
67
67
 
68
- SELECT:: select, select_all, select_append, select_group, select_more
68
+ SELECT:: select, select_all, select_append, select_group, select_more, select_prepend
69
69
  FROM:: from, from_self
70
70
  JOIN:: join, left_join, right_join, full_join, natural_join, natural_left_join, natural_right_join, natural_full_join, cross_join, inner_join, left_outer_join, right_outer_join, full_outer_join, join_table
71
71
  WHERE:: where, filter, exclude, or, grep, invert, unfiltered
@@ -48,7 +48,7 @@ If you want to change mass assignment so it ignores attempts to access restricte
48
48
  Since mass assignment by default allows modification of all column values except for primary key columns, it can be a security risk in some cases.
49
49
  If you are dealing with untrusted input, you are generally going to want to restrict what should be updated.
50
50
 
51
- Sequel has <tt>Model#set_fields</tt> and <tt>Model#update_fields</tt> methods, which are designed to be used with untrused input.
51
+ Sequel has <tt>Model#set_fields</tt> and <tt>Model#update_fields</tt> methods, which are designed to be used with untrusted input.
52
52
  These methods take two arguments, the untrusted hash as the first argument, and a trusted array of field names as the second argument:
53
53
 
54
54
  post.set_fields({title: 'T', body: 'B'}, [:title, :body])
data/doc/migration.rdoc CHANGED
@@ -86,9 +86,24 @@ the following methods:
86
86
  * +add_full_text_index+
87
87
  * +add_spatial_index+
88
88
  * +rename_column+
89
+ * +set_column_allow_null+
89
90
 
90
91
  If you use any other methods, you should create your own +down+ block.
91
92
 
93
+ To revert a migration created with +change+, you can copy the migration to a new file, and
94
+ replace +change+ with +revert+. For example, if you no longer need the artists table, you
95
+ can use the following migration. This will drop the artists table when migrating up, and
96
+ recreate it when migrating down:
97
+
98
+ Sequel.migration do
99
+ revert do
100
+ create_table(:artists) do
101
+ primary_key :id
102
+ String :name, null: false
103
+ end
104
+ end
105
+ end
106
+
92
107
  In normal usage, when Sequel's migrator runs, it runs the +up+ blocks for all
93
108
  migrations that have not yet been applied. However, you can use the <tt>-M</tt>
94
109
  switch to specify the version to which to migrate, and if it is lower than the
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
 
@@ -268,7 +268,7 @@ The following additional options are supported:
268
268
  to MySQL.
269
269
  :socket :: Can be used to specify a Unix socket file to connect to instead of a TCP host and port.
270
270
  :sql_mode :: Set the sql_mode(s) for a given connection. Can be single symbol or string,
271
- 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>).
272
272
  :timeout :: Sets the wait_timeout for the connection, defaults to 1 month.
273
273
  :read_timeout :: Set the timeout in seconds for reading back results to a query.
274
274
  :connect_timeout :: Set the timeout in seconds before a connection attempt is abandoned
@@ -279,7 +279,7 @@ if either the :sslca or :sslkey option is given.
279
279
 
280
280
  === mysql2
281
281
 
282
- This is a newer MySQL adapter that does typecasting in C, so it is often faster than the
282
+ This is a MySQL adapter that does typecasting in C, so it is often faster than the
283
283
  mysql adapter. The options given are passed to Mysql2::Client.new, see the mysql2 documentation
284
284
  for details on what options are supported. The :timeout, :auto_is_null, :sql_mode, and :disable_split_materialized
285
285
  options supported by the mysql adapter are also supported for mysql2 adapter (and any other adapters connecting to
@@ -290,13 +290,13 @@ mysql, such as the jdbc/mysql adapter).
290
290
  The ODBC adapter allows you to connect to any database with the appropriate ODBC drivers installed.
291
291
  The :database option given ODBC database should be the DSN (Descriptive Service Name) from the ODBC configuration.
292
292
 
293
- Sequel.odbc('mydb', :user => "user", :password => "password")
293
+ Sequel.odbc('mydb', user: "user", password: "password")
294
294
 
295
295
  The :host and :port options are not respected. The following additional options are supported:
296
296
 
297
297
  :db_type :: Can be specified as 'mssql', 'progress', or 'db2' to use SQL syntax specific to those databases.
298
298
  :drvconnect :: Can be given an ODBC connection string, and will use ODBC::Database#drvconnect to
299
- 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>
300
300
 
301
301
  === oracle
302
302
 
@@ -345,7 +345,9 @@ The following additional options are supported:
345
345
  :search_path :: Set to the schema search_path. This can either be a single string containing the schemas
346
346
  separated by commas (for use via a URL: <tt>postgres:///?search_path=schema1,schema2</tt>), or it
347
347
  can be an array of strings (for use via an option:
348
- <tt>Sequel.postgres(:search_path=>['schema1', 'schema2'])</tt>).
348
+ <tt>Sequel.postgres(search_path: ['schema1', 'schema2'])</tt>).
349
+ :unlogged_tables_default :: Set to true to use UNLOGGED by default for created tables, for potentially better performance
350
+ when data integrity is not important.
349
351
  :use_iso_date_format :: This can be set to false to not force the ISO date format. Sequel forces
350
352
  it by default to allow for an optimization.
351
353
 
@@ -388,8 +390,10 @@ The following additional options are supported:
388
390
  :readonly :: open database in read-only mode
389
391
  :timeout :: the busy timeout to use in milliseconds (default: 5000).
390
392
  :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.
393
+ allows you to use regexp support in dataset expressions. If +:cached+ or <tt>"cached"</tt>+, caches each
394
+ unique regex (more efficient but risk of memory leak). If a Proc is provided, it will be called with
395
+ a string for the regexp and a string for the value to compare, and should return whether the regexp
396
+ string matches the string value to compare. The default Proc used does <tt>Regexp.new(regexp_str).match(str)</tt>.
393
397
 
394
398
  Note that SQLite memory databases are restricted to a single connection by
395
399
  default. This is because SQLite does not allow multiple connections to
@@ -423,3 +427,10 @@ Other Sequel specific options:
423
427
  This should be specified as an integer. If you plan on setting large
424
428
  text or blob values via tinytds, you should use this option or modify
425
429
  your freetds.conf file.
430
+
431
+ === trilogy
432
+
433
+ This is a MySQL adapter that does typecasting in C, and does not require any mysql client libraries installed.
434
+ The options given are passed to Trilogy.new, see the trilogy documentation for details on what options are
435
+ supported. The :timeout, :auto_is_null, :sql_mode, and :disable_split_materialized
436
+ options supported by the mysql adapter are also supported for trilogy adapter.
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
 
@@ -561,7 +561,7 @@ such as the related table and column or constraint.
561
561
 
562
562
  DB.create_table(:test1){primary_key :id}
563
563
  DB.create_table(:test2){primary_key :id; foreign_key :test1_id, :test1}
564
- DB[:test2].insert(:test1_id=>1) rescue DB.error_info($!)
564
+ DB[:test2].insert(test1_id: 1) rescue DB.error_info($!)
565
565
  # => {
566
566
  # :schema=>"public",
567
567
  # :table=>"test2",
data/doc/querying.rdoc CHANGED
@@ -624,11 +624,16 @@ Like +order+, +select+ replaces the existing selected columns:
624
624
  Artist.select(:id).select(:name)
625
625
  # SELECT name FROM artists
626
626
 
627
- To add to the existing selected columns, use +select_append+:
627
+ To append to the existing selected columns, use +select_append+:
628
628
 
629
629
  Artist.select(:id).select_append(:name)
630
630
  # SELECT id, name FROM artists
631
631
 
632
+ To prepend to the existing selected columns, use +select_prepend+:
633
+
634
+ Artist.select(:id).select_prepend(:name)
635
+ # SELECT name, id FROM artists
636
+
632
637
  To remove specifically selected columns, and default back to all
633
638
  columns, use +select_all+:
634
639
 
@@ -715,7 +720,7 @@ aggregation:
715
720
 
716
721
  Album.select_group(:artist_id).select_append{sum(num_tracks).as(tracks)}
717
722
  # SELECT artist_id, sum(num_tracks) AS tracks FROM albums GROUP BY artist_id
718
-
723
+
719
724
  == Having
720
725
 
721
726
  The SQL HAVING clause is similar to the WHERE clause, except that
@@ -0,0 +1,43 @@
1
+ = Improvements
2
+
3
+ * When typecasting strings to other types, Sequel::Database will now
4
+ by default not typecast strings that are much longer than expected
5
+ for the underlying type. Depending on the underlying type, there
6
+ is a limit of either 100 or 1000 bytes on the input string. This
7
+ avoids potential performance issues when trying to convert
8
+ arbitrary sized user input to specific types.
9
+
10
+ * The respond_to? to defined? change made in 5.60.0 was reverted in
11
+ 5.60.1 as it broke cases on Ruby < 3 where the object had an unused
12
+ refinement that added the method.
13
+
14
+ * When typecasting strings to integer, strings such as -0xa are now
15
+ treated as negative hexidecimal strings, similar to how 0xa is
16
+ treated as a positive hexidecimal string.
17
+
18
+ * Database#foreign_key_list now returns results for partitioned
19
+ tables on PostgreSQL 11+.
20
+
21
+ * Timestamps before the date of calendar reform are now handled
22
+ correctly by the pg_extended_date_support extension when using
23
+ Ruby 3.2 preview 2+.
24
+
25
+ = Backwards Compatibility
26
+
27
+ * The change to not typecast strings that are too long can break
28
+ backwards compatibility for applications that expect typecasting
29
+ for input beyond Sequel's limits. You can disable the string
30
+ bytesize checking by setting:
31
+
32
+ DB.check_string_typecast_bytesize = false
33
+
34
+ or by passing the check_string_typecast_bytesize: false option when
35
+ creating the Database instance.
36
+
37
+ * Code to workaround a bug in JRuby 9.2.0.0 has been removed from the
38
+ pg_extended_date_support extension. Users of the extension should
39
+ upgrade to a newer JRuby version.
40
+
41
+ * The is_json and is_not_json methods have been removed from the
42
+ pg_json_ops extension, as the underlying support was removed in
43
+ PostgreSQL 15 beta 4.
@@ -0,0 +1,132 @@
1
+ = New Features
2
+
3
+ * The pg_auto_parameterize extension for automatically using bound
4
+ variables when using postgres adapter with the pg driver has been
5
+ added back to Sequel. This extension was originally added in Sequel
6
+ 3.34.0, but was removed in 4.0.0 due to the many corner cases it
7
+ had. Almost all of the corner cases have now been fixed, and
8
+ the extension is now recommended for production use. Compared
9
+ to the original version in Sequel 3, the reintroduced version
10
+ of the extension includes the following changes:
11
+
12
+ * Handles integers used in LIMIT/ORDER
13
+ * Respects explicit CASTs
14
+ * Tries to convert column IN (int, ...) into column = ANY($) with an
15
+ array parameter
16
+ * Uses the same parameter for the same object used more than once in
17
+ a query
18
+ * Uses parameters when inserting multiple rows via Dataset#import
19
+ * Supports automatically parameterizing all of the
20
+ PostgreSQL-specific types that Sequel ships support for in pg_*
21
+ extensions (though some values of those types may not support
22
+ automatic parameterization).
23
+ * Supports skipping auto parameterization for specific values.
24
+
25
+ Automatic parameterization is generally slower than Sequel's default
26
+ behavior, since some optimizations Sequel uses by default do not
27
+ currently support automatic parameterization.
28
+
29
+ Applications may need changes to work correctly with the
30
+ pg_auto_parameterize extension, such as the addition of explicit
31
+ casts. Please read the extension documentation for more details.
32
+
33
+ * Integer column schema entries now include :min_value and :max_value
34
+ entries on most databases, indicating the minimum and maximum values
35
+ supported for the column.
36
+
37
+ The validation_helpers plugin now has validates_max_value and
38
+ validates_min_value for testing the column value is not greater
39
+ than the given maximum value and not less than the given minimum
40
+ value, respectively.
41
+
42
+ The auto_validations plugin now automatically uses the :min_value
43
+ and :max_value column schema entries with the new validation_helpers
44
+ methods to validate that the column values for integer columns are
45
+ in the allowed range.
46
+
47
+ * A primary_key_lookup_check_values plugin has been added for
48
+ automatically typecasting and checking the primary key values are
49
+ in the allowed range (given by :min_value and :max_value column
50
+ schema entries) during lookup. If typecasting fails or the value
51
+ is outside the allowed range, the primary key lookup will return
52
+ nil without issuing a query (or will raise a NoMatchingRow error
53
+ if using with_pk!).
54
+
55
+ Note that this can change behavior in some cases if you are
56
+ passing filter conditions during lookup instead of passing primary
57
+ key values. The plugin tries to support most common filter
58
+ conditions, but there are still cases that will break.
59
+
60
+ * Sequel now supports shard-specific :after_connect and :connect_sqls
61
+ Database options, allowing you to customize behavior for specific
62
+ shards:
63
+
64
+ DB = Sequel.connect('url', servers: {
65
+ :shard1 => {host: '...', after_connect: proc{|conn|}},
66
+ :shard2 => {host: '...', connect_sqls: ['...']},
67
+ })
68
+
69
+ Note that these shard-specific options will not be respected if you
70
+ are calling after_connect= or connect_sqls= on the Database's
71
+ connection pool.
72
+
73
+ = Other Improvements
74
+
75
+ * A Sequel::Postgres::IntegerOutsideBigintRange exception will now be
76
+ raised if trying to literalize an integer outside PostgreSQL bigint
77
+ range, to avoid PostgreSQL treating the integer as a numeric type
78
+ and not respecting indexes on the related column.
79
+
80
+ A pg_extended_integer_support extension has been added for
81
+ customizing the behavior when literalizing an integer outside
82
+ PostgreSQL bigint range, either quoting it or getting the
83
+ historical behavior of using it directly in the query.
84
+
85
+ * Dataset#import and #multi_insert no longer use transactions when
86
+ they only run a single query.
87
+
88
+ * Fractional seconds in timestamps are now respected in the
89
+ named_timezones extension.
90
+
91
+ * Using hstore[] types as bound variables now works on PostgreSQL.
92
+
93
+ * Using BC dates and timestamps in bound variables now works on
94
+ PostgreSQL.
95
+
96
+ * A corner case has been fixed in eager loading where the window
97
+ function eager limit strategy would be used without removing the
98
+ row_number entries from the result.
99
+
100
+ * The shared postgres adapter now caches reflection datasets, speeding
101
+ up Database#indexes and similar methods.
102
+
103
+ * The mock postgres adapter now assumes PostgreSQL 15 instead of
104
+ PostgreSQL 14 by default.
105
+
106
+ = Backwards Compatibility
107
+
108
+ * If you are using Ruby integers outside PostgreSQL bigint range when
109
+ dealing with PostgreSQL numeric column values, this version may
110
+ not be compatible. It is recommended you explicitly convert the
111
+ Ruby integers to BigDecimal objects if you are using them for
112
+ numeric column values. You can also use the
113
+ pg_extended_integer_support extension introduced in this version.
114
+
115
+ = Workaround for Older Versions
116
+
117
+ * If you cannot upgrade to Sequel 5.62.0, but still want to avoid the
118
+ problems that come from using literal large integers on PostgreSQL,
119
+ you can use the following code, where DB is your Sequel::Database
120
+ object:
121
+
122
+ DB.extend_datasets do
123
+ def literal_integer(v)
124
+ if v > 9223372036854775807 || v < -9223372036854775808
125
+ raise Sequel::InvalidValue, "PostgreSQL int too large: #{v}"
126
+ end
127
+ super
128
+ end
129
+ end
130
+
131
+ This workaround should work all the way back to Sequel 3.29.0,
132
+ released in November 2011.