sequel 5.45.0 → 5.77.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +434 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +59 -27
  5. data/bin/sequel +11 -3
  6. data/doc/advanced_associations.rdoc +16 -14
  7. data/doc/association_basics.rdoc +119 -24
  8. data/doc/cheat_sheet.rdoc +11 -3
  9. data/doc/mass_assignment.rdoc +1 -1
  10. data/doc/migration.rdoc +27 -6
  11. data/doc/model_hooks.rdoc +1 -1
  12. data/doc/object_model.rdoc +8 -8
  13. data/doc/opening_databases.rdoc +28 -12
  14. data/doc/postgresql.rdoc +16 -8
  15. data/doc/querying.rdoc +5 -3
  16. data/doc/release_notes/5.46.0.txt +87 -0
  17. data/doc/release_notes/5.47.0.txt +59 -0
  18. data/doc/release_notes/5.48.0.txt +14 -0
  19. data/doc/release_notes/5.49.0.txt +59 -0
  20. data/doc/release_notes/5.50.0.txt +78 -0
  21. data/doc/release_notes/5.51.0.txt +47 -0
  22. data/doc/release_notes/5.52.0.txt +87 -0
  23. data/doc/release_notes/5.53.0.txt +23 -0
  24. data/doc/release_notes/5.54.0.txt +27 -0
  25. data/doc/release_notes/5.55.0.txt +21 -0
  26. data/doc/release_notes/5.56.0.txt +51 -0
  27. data/doc/release_notes/5.57.0.txt +23 -0
  28. data/doc/release_notes/5.58.0.txt +31 -0
  29. data/doc/release_notes/5.59.0.txt +73 -0
  30. data/doc/release_notes/5.60.0.txt +22 -0
  31. data/doc/release_notes/5.61.0.txt +43 -0
  32. data/doc/release_notes/5.62.0.txt +132 -0
  33. data/doc/release_notes/5.63.0.txt +33 -0
  34. data/doc/release_notes/5.64.0.txt +50 -0
  35. data/doc/release_notes/5.65.0.txt +21 -0
  36. data/doc/release_notes/5.66.0.txt +24 -0
  37. data/doc/release_notes/5.67.0.txt +32 -0
  38. data/doc/release_notes/5.68.0.txt +61 -0
  39. data/doc/release_notes/5.69.0.txt +26 -0
  40. data/doc/release_notes/5.70.0.txt +35 -0
  41. data/doc/release_notes/5.71.0.txt +21 -0
  42. data/doc/release_notes/5.72.0.txt +33 -0
  43. data/doc/release_notes/5.73.0.txt +66 -0
  44. data/doc/release_notes/5.74.0.txt +45 -0
  45. data/doc/release_notes/5.75.0.txt +35 -0
  46. data/doc/release_notes/5.76.0.txt +86 -0
  47. data/doc/release_notes/5.77.0.txt +63 -0
  48. data/doc/schema_modification.rdoc +1 -1
  49. data/doc/security.rdoc +9 -9
  50. data/doc/sharding.rdoc +3 -1
  51. data/doc/sql.rdoc +27 -15
  52. data/doc/testing.rdoc +23 -13
  53. data/doc/transactions.rdoc +6 -6
  54. data/doc/virtual_rows.rdoc +1 -1
  55. data/lib/sequel/adapters/ado/access.rb +1 -1
  56. data/lib/sequel/adapters/ado.rb +1 -1
  57. data/lib/sequel/adapters/amalgalite.rb +3 -5
  58. data/lib/sequel/adapters/ibmdb.rb +3 -3
  59. data/lib/sequel/adapters/jdbc/derby.rb +8 -0
  60. data/lib/sequel/adapters/jdbc/h2.rb +63 -10
  61. data/lib/sequel/adapters/jdbc/hsqldb.rb +8 -0
  62. data/lib/sequel/adapters/jdbc/postgresql.rb +7 -4
  63. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +15 -0
  64. data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -0
  65. data/lib/sequel/adapters/jdbc.rb +24 -22
  66. data/lib/sequel/adapters/mysql.rb +92 -67
  67. data/lib/sequel/adapters/mysql2.rb +56 -51
  68. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  69. data/lib/sequel/adapters/odbc.rb +1 -1
  70. data/lib/sequel/adapters/oracle.rb +4 -3
  71. data/lib/sequel/adapters/postgres.rb +89 -45
  72. data/lib/sequel/adapters/shared/access.rb +11 -1
  73. data/lib/sequel/adapters/shared/db2.rb +42 -0
  74. data/lib/sequel/adapters/shared/mssql.rb +91 -10
  75. data/lib/sequel/adapters/shared/mysql.rb +78 -3
  76. data/lib/sequel/adapters/shared/oracle.rb +86 -7
  77. data/lib/sequel/adapters/shared/postgres.rb +576 -171
  78. data/lib/sequel/adapters/shared/sqlanywhere.rb +21 -5
  79. data/lib/sequel/adapters/shared/sqlite.rb +92 -8
  80. data/lib/sequel/adapters/sqlanywhere.rb +1 -1
  81. data/lib/sequel/adapters/sqlite.rb +99 -18
  82. data/lib/sequel/adapters/tinytds.rb +1 -1
  83. data/lib/sequel/adapters/trilogy.rb +117 -0
  84. data/lib/sequel/adapters/utils/columns_limit_1.rb +22 -0
  85. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  86. data/lib/sequel/ast_transformer.rb +6 -0
  87. data/lib/sequel/connection_pool/sharded_single.rb +5 -7
  88. data/lib/sequel/connection_pool/sharded_threaded.rb +16 -11
  89. data/lib/sequel/connection_pool/sharded_timed_queue.rb +374 -0
  90. data/lib/sequel/connection_pool/single.rb +6 -8
  91. data/lib/sequel/connection_pool/threaded.rb +14 -8
  92. data/lib/sequel/connection_pool/timed_queue.rb +270 -0
  93. data/lib/sequel/connection_pool.rb +57 -31
  94. data/lib/sequel/core.rb +17 -18
  95. data/lib/sequel/database/connecting.rb +27 -3
  96. data/lib/sequel/database/dataset.rb +16 -6
  97. data/lib/sequel/database/misc.rb +70 -14
  98. data/lib/sequel/database/query.rb +73 -2
  99. data/lib/sequel/database/schema_generator.rb +11 -6
  100. data/lib/sequel/database/schema_methods.rb +23 -4
  101. data/lib/sequel/database/transactions.rb +6 -0
  102. data/lib/sequel/dataset/actions.rb +111 -15
  103. data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +42 -0
  104. data/lib/sequel/dataset/features.rb +20 -1
  105. data/lib/sequel/dataset/misc.rb +12 -2
  106. data/lib/sequel/dataset/placeholder_literalizer.rb +20 -9
  107. data/lib/sequel/dataset/query.rb +170 -41
  108. data/lib/sequel/dataset/sql.rb +190 -71
  109. data/lib/sequel/dataset.rb +4 -0
  110. data/lib/sequel/extensions/_model_pg_row.rb +0 -12
  111. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  112. data/lib/sequel/extensions/any_not_empty.rb +2 -2
  113. data/lib/sequel/extensions/async_thread_pool.rb +14 -13
  114. data/lib/sequel/extensions/auto_cast_date_and_time.rb +94 -0
  115. data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
  116. data/lib/sequel/extensions/connection_expiration.rb +15 -9
  117. data/lib/sequel/extensions/connection_validator.rb +16 -11
  118. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  119. data/lib/sequel/extensions/core_refinements.rb +36 -11
  120. data/lib/sequel/extensions/date_arithmetic.rb +36 -8
  121. data/lib/sequel/extensions/date_parse_input_handler.rb +67 -0
  122. data/lib/sequel/extensions/datetime_parse_to_time.rb +5 -1
  123. data/lib/sequel/extensions/duplicate_columns_handler.rb +11 -10
  124. data/lib/sequel/extensions/index_caching.rb +5 -1
  125. data/lib/sequel/extensions/inflector.rb +1 -1
  126. data/lib/sequel/extensions/is_distinct_from.rb +141 -0
  127. data/lib/sequel/extensions/looser_typecasting.rb +3 -0
  128. data/lib/sequel/extensions/migration.rb +57 -15
  129. data/lib/sequel/extensions/named_timezones.rb +22 -6
  130. data/lib/sequel/extensions/pagination.rb +1 -1
  131. data/lib/sequel/extensions/pg_array.rb +33 -4
  132. data/lib/sequel/extensions/pg_array_ops.rb +2 -2
  133. data/lib/sequel/extensions/pg_auto_parameterize.rb +509 -0
  134. data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +110 -0
  135. data/lib/sequel/extensions/pg_enum.rb +1 -2
  136. data/lib/sequel/extensions/pg_extended_date_support.rb +39 -28
  137. data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
  138. data/lib/sequel/extensions/pg_hstore.rb +6 -1
  139. data/lib/sequel/extensions/pg_hstore_ops.rb +53 -3
  140. data/lib/sequel/extensions/pg_inet.rb +10 -11
  141. data/lib/sequel/extensions/pg_inet_ops.rb +1 -1
  142. data/lib/sequel/extensions/pg_interval.rb +11 -11
  143. data/lib/sequel/extensions/pg_json.rb +13 -15
  144. data/lib/sequel/extensions/pg_json_ops.rb +125 -2
  145. data/lib/sequel/extensions/pg_multirange.rb +367 -0
  146. data/lib/sequel/extensions/pg_range.rb +13 -26
  147. data/lib/sequel/extensions/pg_range_ops.rb +37 -9
  148. data/lib/sequel/extensions/pg_row.rb +20 -19
  149. data/lib/sequel/extensions/pg_row_ops.rb +1 -1
  150. data/lib/sequel/extensions/pg_timestamptz.rb +27 -3
  151. data/lib/sequel/extensions/round_timestamps.rb +1 -1
  152. data/lib/sequel/extensions/s.rb +2 -1
  153. data/lib/sequel/extensions/schema_caching.rb +1 -1
  154. data/lib/sequel/extensions/schema_dumper.rb +45 -11
  155. data/lib/sequel/extensions/server_block.rb +10 -13
  156. data/lib/sequel/extensions/set_literalizer.rb +58 -0
  157. data/lib/sequel/extensions/sql_comments.rb +110 -3
  158. data/lib/sequel/extensions/sql_log_normalizer.rb +108 -0
  159. data/lib/sequel/extensions/sqlite_json_ops.rb +255 -0
  160. data/lib/sequel/extensions/string_agg.rb +1 -1
  161. data/lib/sequel/extensions/string_date_time.rb +19 -23
  162. data/lib/sequel/extensions/symbol_aref.rb +2 -0
  163. data/lib/sequel/extensions/transaction_connection_validator.rb +78 -0
  164. data/lib/sequel/model/associations.rb +286 -92
  165. data/lib/sequel/model/base.rb +53 -33
  166. data/lib/sequel/model/dataset_module.rb +3 -0
  167. data/lib/sequel/model/errors.rb +10 -1
  168. data/lib/sequel/model/exceptions.rb +15 -3
  169. data/lib/sequel/model/inflections.rb +1 -1
  170. data/lib/sequel/plugins/auto_restrict_eager_graph.rb +62 -0
  171. data/lib/sequel/plugins/auto_validations.rb +74 -16
  172. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  173. data/lib/sequel/plugins/column_encryption.rb +29 -8
  174. data/lib/sequel/plugins/composition.rb +3 -2
  175. data/lib/sequel/plugins/concurrent_eager_loading.rb +4 -4
  176. data/lib/sequel/plugins/constraint_validations.rb +8 -5
  177. data/lib/sequel/plugins/defaults_setter.rb +16 -0
  178. data/lib/sequel/plugins/dirty.rb +1 -1
  179. data/lib/sequel/plugins/enum.rb +124 -0
  180. data/lib/sequel/plugins/finder.rb +4 -2
  181. data/lib/sequel/plugins/insert_conflict.rb +4 -0
  182. data/lib/sequel/plugins/instance_specific_default.rb +1 -1
  183. data/lib/sequel/plugins/json_serializer.rb +2 -2
  184. data/lib/sequel/plugins/lazy_attributes.rb +3 -0
  185. data/lib/sequel/plugins/list.rb +8 -3
  186. data/lib/sequel/plugins/many_through_many.rb +109 -10
  187. data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -38
  188. data/lib/sequel/plugins/nested_attributes.rb +4 -4
  189. data/lib/sequel/plugins/optimistic_locking.rb +9 -42
  190. data/lib/sequel/plugins/optimistic_locking_base.rb +55 -0
  191. data/lib/sequel/plugins/paged_operations.rb +181 -0
  192. data/lib/sequel/plugins/pg_array_associations.rb +46 -34
  193. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +9 -3
  194. data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +109 -0
  195. data/lib/sequel/plugins/prepared_statements.rb +12 -2
  196. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -1
  197. data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
  198. data/lib/sequel/plugins/rcte_tree.rb +7 -4
  199. data/lib/sequel/plugins/require_valid_schema.rb +67 -0
  200. data/lib/sequel/plugins/serialization.rb +1 -0
  201. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -0
  202. data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
  203. data/lib/sequel/plugins/sql_comments.rb +189 -0
  204. data/lib/sequel/plugins/static_cache.rb +39 -1
  205. data/lib/sequel/plugins/static_cache_cache.rb +5 -1
  206. data/lib/sequel/plugins/subclasses.rb +28 -11
  207. data/lib/sequel/plugins/tactical_eager_loading.rb +23 -10
  208. data/lib/sequel/plugins/timestamps.rb +1 -1
  209. data/lib/sequel/plugins/unused_associations.rb +521 -0
  210. data/lib/sequel/plugins/update_or_create.rb +1 -1
  211. data/lib/sequel/plugins/validate_associated.rb +22 -12
  212. data/lib/sequel/plugins/validation_helpers.rb +41 -11
  213. data/lib/sequel/plugins/validation_helpers_generic_type_messages.rb +73 -0
  214. data/lib/sequel/plugins/xml_serializer.rb +1 -1
  215. data/lib/sequel/sql.rb +1 -1
  216. data/lib/sequel/timezones.rb +12 -14
  217. data/lib/sequel/version.rb +1 -1
  218. metadata +109 -19
@@ -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
@@ -276,22 +279,24 @@ if either the :sslca or :sslkey option is given.
276
279
 
277
280
  === mysql2
278
281
 
279
- 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
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,11 @@ 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. If +:cached+ or <tt>"cached"</tt>+, caches each
392
+ unique regex (more efficient but risk of memory leak). If a Proc is provided, it will be called with
393
+ a string for the regexp and a string for the value to compare, and should return whether the regexp
394
+ string matches the string value to compare. The default Proc used does <tt>Regexp.new(regexp_str).match(str)</tt>.
386
395
 
387
396
  Note that SQLite memory databases are restricted to a single connection by
388
397
  default. This is because SQLite does not allow multiple connections to
@@ -416,3 +425,10 @@ Other Sequel specific options:
416
425
  This should be specified as an integer. If you plan on setting large
417
426
  text or blob values via tinytds, you should use this option or modify
418
427
  your freetds.conf file.
428
+
429
+ === trilogy
430
+
431
+ This is a MySQL adapter that does typecasting in C, and does not require any mysql client libraries installed.
432
+ The options given are passed to Trilogy.new, see the trilogy documentation for details on what options are
433
+ supported. The :timeout, :auto_is_null, :sql_mode, and :disable_split_materialized
434
+ 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
 
@@ -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,87 @@
1
+ = New Features
2
+
3
+ * An unused_associations plugin has been added, which allows you to
4
+ determine which associations and association methods are not used.
5
+ You can use this to avoid defining the unused associations and
6
+ association methods, which can save memory.
7
+
8
+ This plugin is supported on Ruby 2.5+, and uses method coverage to
9
+ determine if the plugin's methods are called. Because Sequel::Model
10
+ adds association methods to an anonymous module included in the
11
+ class, directly using the method coverage data to determine which
12
+ associations are used is challenging.
13
+
14
+ This plugin is mostly designed for reporting. You can have a
15
+ test suite that runs with method coverage enabled, and use the
16
+ coverage information to get data on unused associations:
17
+
18
+ # Calls Coverage.result
19
+ cov_data = Sequel::Model.update_associations_coverage
20
+ unused_associations_data = Sequel::Model.update_unused_associations_data(coverage_data: cov_data)
21
+ Sequel::Model.unused_associations(unused_associations_data: unused_associations_data)
22
+ # => [["Class1", "assoc1"], ...]
23
+
24
+ unused_associations returns an array of two element arrays, where
25
+ the first element is the class name and the second element is the
26
+ association name. The returned values will be associations where
27
+ all of the association methods are not used.
28
+
29
+ In addition to determining which associations are not used, you can
30
+ also use this to determine if you are defining association methods
31
+ that are not used:
32
+
33
+ Sequel::Model.unused_association_options(unused_associations_data: unused_associations_data)
34
+ # => [["Class2", "assoc2", {:read_only=>true}], ...]
35
+
36
+ unused_association_options is similar to unused_associations, but
37
+ returns an array of three element arrays, where the third element
38
+ is a hash of association options that should be used to avoid
39
+ defining the unused association methods. It's common in Sequel to
40
+ define associations and only use them for reading data and not for
41
+ modifications, and you can use this to easily see which associations
42
+ are only used for reading data.
43
+
44
+ As the determination of whether associations are used is based on
45
+ method coverage, this will report as unused any associations that are
46
+ used but where the association methods are not called. These cases
47
+ are rare, but can happen if you have libraries that use the
48
+ association reflection metadata without calling the association
49
+ methods, or use the association only in combination with another
50
+ plugin such as dataset_associations. You can set the :is_used
51
+ association option to explicitly mark an association as used, and
52
+ have this plugin avoid reporting it as unused.
53
+
54
+ In addition to just reporting on unused associations, you can also
55
+ directly use the unused associations metadata to automatically avoid
56
+ defining unused associations or unused associations methods. You
57
+ can set a :file option when loading the plugin:
58
+
59
+ Sequel::Model.plugin :unused_associations, file: 'unused_associations.json'
60
+
61
+ Then run the method coverage testing. This will save the unused
62
+ associations metadata to the file. Then you can use this metadata
63
+ automatically by also setting the :modify_associations option:
64
+
65
+ Sequel::Model.plugin :unused_associations, file: 'unused_associations.json',
66
+ modify_associations: true
67
+
68
+ With the :modify_associations option, unused associations are
69
+ skipped instead of being defined, and the options returned by
70
+ unused_association_options are automatically used. Note that using
71
+ the :modify_associations option is risky unless you have complete
72
+ coverage and do not have cases where the associations are used
73
+ without calling methods.
74
+
75
+ It is common to have multiple test suites where you need to combine
76
+ coverage. The plugin supports this by using a :coverage_file option:
77
+
78
+ Sequel::Model.plugin :unused_associations, coverage_file: 'unused_associations_coverage.json'
79
+
80
+ In this case, you would run update_associations_coverage after each
81
+ test suite, and update_unused_associations_data only after all test
82
+ suites have been run.
83
+
84
+ * Passing nil as the value of the :setter, :adder, :remover, or
85
+ :clearer association options will cause the related method to not be
86
+ defined, instead of using the default value. This allows you to
87
+ only define the methods you will actually be using.
@@ -0,0 +1,59 @@
1
+ = New Features
2
+
3
+ * Sequel now supports using separate queries for each table for both
4
+ lazy and eager loading of the following associations:
5
+
6
+ * many_to_many
7
+ * one_through_one
8
+ * many_through_many # many_through_many plugin
9
+ * one_through_many # many_through_many plugin
10
+
11
+ For many_to_many/one_through_one, you specify the :join_table_db
12
+ association option, which should be a Sequel::Database instance
13
+ containing the join table. It is possible for the current table,
14
+ join table, and associated table all to be in separate databases:
15
+
16
+ JOIN_TABLE_DB = Sequel.connect('...')
17
+ Album.many_to_many :artists, join_table_db: JOIN_TABLE_DB
18
+
19
+ For many_through_many/one_through_many, you can use the :db option
20
+ in each join table specification. All join tables can be in
21
+ separate databases:
22
+
23
+ JTDB1 = Sequel.connect('...')
24
+ JTDB2 = Sequel.connect('...')
25
+ # Tracks on all albums this artist appears on
26
+ Artist.many_through_many :album_tracks, [
27
+ {table: :albums_artists, left: :artist_id, right: :album_id, db: JTDB1},
28
+ {table: :artists, left: :id, right: :id, db: JTDB2}
29
+ ],
30
+ class: :Track, right_primary_key: :album_id
31
+
32
+ * The :allow_eager_graph association option has been added. Setting
33
+ this option to false will disallow eager loading via #eager_graph.
34
+ This is useful if you can eager load the association via #eager,
35
+ but not with #eager_graph.
36
+
37
+ * The :allow_filtering_by association option has been added. Setting
38
+ this option to false will disallow the use of filtering by
39
+ associations for the association.
40
+
41
+ * Dataset#returning is now supported on SQLite 3.35.0+. To work around
42
+ bugs in the SQLite implementation, identifiers used in the RETURNING
43
+ clause are automatically aliased. Additionally, prepared statements
44
+ that use the RETURNING clause on SQLite seem to have issues, so the
45
+ prepared_statements plugin does not automatically use prepared
46
+ statements on SQLite for queries that use the RETURNING clause.
47
+
48
+ * Database#rename_tables has been added on MySQL to support renaming
49
+ multiple tables in the same query.
50
+
51
+ = Other Improvements
52
+
53
+ * The unused_associations plugin now tracks access to the association
54
+ reflection for associations, so it will no longer show an
55
+ association as completely unused if something is accessing the
56
+ association reflection for it. This eliminates most of the false
57
+ positives, where the plugin would show an association as unused
58
+ even though something was using it without calling the association
59
+ methods.
@@ -0,0 +1,14 @@
1
+ = New Features
2
+
3
+ * A Sequel::Database#like_without_collate accessor has been added on
4
+ Microsoft SQL Server, which avoids using the COLLATE clause for
5
+ LIKE expressions. This can speed up query performance significantly.
6
+
7
+ * A private Sequel::Model::Errors#full_message method has been added
8
+ to make it easier to support internationalization for Sequel::Model
9
+ error messages.
10
+
11
+ = Other Improvements
12
+
13
+ * The association reflection tracking in the unused_associations
14
+ plugin now works correctly when combining coverage runs.
@@ -0,0 +1,59 @@
1
+ = New Features
2
+
3
+ * Model#validates_no_null_byte has been added to the
4
+ validation_helpers. It checks that the value being validated does
5
+ not contain an ASCII NUL ('\0') byte. Some databases will return an
6
+ error if a string contains a NUL byte.
7
+
8
+ The auto_validations plugin will now automatically add no_null_byte
9
+ validations for all string columns in the model's table. This will
10
+ change exceptions raised by NUL bytes from database errors to
11
+ validation failures.
12
+
13
+ If you are using auto_validations and would like to have a table
14
+ accept NUL bytes in string columns, use the following code inside
15
+ the model:
16
+
17
+ skip_auto_validations(:no_null_byte)
18
+
19
+ * JSONB subscripts are now supported on PostgreSQL 14+ when using the
20
+ pg_json_ops extension. You can use JSONB subscripts to more easily
21
+ update part of a JSONB column:
22
+
23
+ DB[:table].update(Sequel.pg_jsonb_op(:column)['key'] => 'value')
24
+ UPDATE "table" SET "column"['key'] = 'value'
25
+
26
+ * hstore subscripts are now supported on PostgreSQL 14+ when using the
27
+ pg_hstore_ops extension. You can use hstore subscripts to more
28
+ easily update part of an hstore column:
29
+
30
+ DB[:table].update(Sequel.hstore_op(:column)['key'] => 'value')
31
+ UPDATE "table" SET "column"['key'] = 'value'
32
+
33
+ * Sequel now supports table aliases for JOIN USING columns on
34
+ PostgreSQL 14+. These allow you to reference the USING columns in
35
+ the query using a qualified identifier. To use this support, pass an
36
+ SQL::AliasedExpression as the expression to join on:
37
+
38
+ DB[:t1].join(:t2, Sequel.as([:c1, :c2], :alias))
39
+ # SELECT * FROM "t1" INNER JOIN "t2" USING ("c1", "c2") AS "alias"
40
+
41
+ * Database#create_trigger on PostgreSQL now supports a :replace option
42
+ for CREATE OR REPLACE TRIGGER (supported in PostgreSQL 14+).
43
+
44
+ * SQL::Expression#sequel_ast_transform has been added to support
45
+ AST transforms of custom expression classes.
46
+
47
+ = Other Improvements
48
+
49
+ * Sequel now supports calling PostgreSQL procedures without arguments
50
+ when using Database#call_procedure. Previously, attempts to call
51
+ procuredures without arguments would call the procedure with a
52
+ single NULL argument.
53
+
54
+ * Sequel now uses defined?(yield) instead of block_given? internally
55
+ for better performance on CRuby. defined?(yield) is faster as it is
56
+ built into the VM, while block_given? is a regular method and has
57
+ the overhead of calling a regular method. Note that defined?(yield)
58
+ is not implemented correctly on JRuby before 9.0.0.0, so this
59
+ release of Sequel drops support for JRuby versions before 9.0.0.0.
@@ -0,0 +1,78 @@
1
+ = New Features
2
+
3
+ * A pg_multirange extension has been added with support for PostgreSQL
4
+ 14+ multirange types. Multirange types are similar to an array of
5
+ ranges, where a value is in the multirange if it is in any of the
6
+ ranges contained in the multirange. Multiranges are useful when you
7
+ need to check against multiple ranges that do not overlap.
8
+
9
+ You can create multiranges using Sequel.pg_multirange, passing
10
+ an array of ranges and a multirange type:
11
+
12
+ DB.extension :pg_multirange
13
+ multirange = Sequel.pg_multirange(array_of_date_ranges, :datemultirange)
14
+
15
+ Sequel.pg_multirange returns a PGMultiRange, which operates as a
16
+ delegate to an array of PGRange objects. Behavior of the object
17
+ is similar to an array, except that cover? is supported, which will
18
+ test if any of the included ranges covers the argument:
19
+
20
+ multirange.cover?(Date.today)
21
+
22
+ Like the pg_range extension, this also supports registering custom
23
+ multirange types, and using multirange types as bound variables.
24
+
25
+ The pg_range_ops extension now supports both ranges and multiranges,
26
+ with a few new methods added to Postgres::RangeOp for converting
27
+ between them:
28
+
29
+ * range_merge
30
+ * multirange
31
+ * and unnest
32
+
33
+ * An sql_log_normalizer extension has been added for normalizing
34
+ logged SQL, replacing numbers and strings inside the SQL string
35
+ with question marks. This is useful for analytics and sensitive
36
+ data.
37
+
38
+ DB[:table].first(a: 1, b: 'something')
39
+ # Without sql_log_normalizer extension, logged SQL is:
40
+ # SELECT * FROM "table" WHERE (("a" = 1) AND ("b" = 'something')) LIMIT 1
41
+
42
+ DB.extension :sql_log_normalizer
43
+ DB[:table].first(a: 1, b: 'something')
44
+ # With sql_log_normalizer_extension, logged SQL is:
45
+ # SELECT * FROM "table" WHERE (("a" = ?) AND ("b" = ?)) LIMIT ?
46
+
47
+ This extension scans the logged SQL for numbers and strings,
48
+ attempting to support the database's rules for string quoting. This
49
+ means it should work with SQL that Sequel didn't itself create.
50
+ However, there are corner cases that the extension doesn't handle,
51
+ such as the use of apostrophes inside quoted identifiers, and
52
+ potentially other cases of database specific SQL where the normal
53
+ string quoting rules are changed, such as the use of escape strings
54
+ on PostgreSQL (E'escape string').
55
+
56
+ * A :before_preconnect Database option has been added. This is useful
57
+ for configuring extensions added via :preconnect_extensions before
58
+ the connection takes place.
59
+
60
+ = Other Improvements
61
+
62
+ * Dataset#columns! now uses a LIMIT 0 query instead of a LIMIT 1 query
63
+ by default. This can improve performance in cases where the row
64
+ returned would be large. Some databases do not support a LIMIT 0
65
+ query, and some adapters that ship with Sequel have been updated to
66
+ continue using LIMIT 1. Custom adapters should be updated to use
67
+ LIMIT 1 if the database does not support LIMIT 0.
68
+
69
+ * The lazy_attributes plugin no longer modifies the database schema.
70
+ Previously, it could modify the database schema indirectly,
71
+ resulting in the loss of typecasting for models that were not
72
+ based on a single table or view, such as usage with the
73
+ class_table_inheritance plugin.
74
+
75
+ * Model#freeze in the composition, serialization, and
76
+ serialization_modification_detection plugins now returns self. In
77
+ addition to being more correct, this fixes usage of these plugins
78
+ with the static_cache plugin.
@@ -0,0 +1,47 @@
1
+ = New Features
2
+
3
+ * On PostgreSQL 14+, Dataset#with_recursive now supports :search and
4
+ :cycle options for result ordering and cycle detection. These use
5
+ the SEARCH and CYCLE clauses added in PostgreSQL 14:
6
+
7
+ DB[:t].with_recursive(:t,
8
+ DB[:i1].where(parent_id: nil),
9
+ DB[:i1].join(:t, id: :parent_id).select_all(:i1),
10
+ search: {by: :id, type: :breadth},
11
+ cycle: {columns: :id, cycle_value: 1, noncycle_value: 2})
12
+
13
+ # WITH RECURSIVE t AS (
14
+ # SELECT * FROM i1 WHERE (parent_id IS NULL)
15
+ # UNION ALL
16
+ # (SELECT i1.* FROM i1 INNER JOIN t ON (t.id = i1.parent_id))
17
+ # )
18
+ # SEARCH BREADTH FIRST BY id SET ordercol
19
+ # CYCLE id SET is_cycle TO 1 DEFAULT 2 USING path
20
+
21
+ * On MySQL, column schema hashes now contain an :extra entry, which
22
+ contains the Extra string returned in MySQL's DESCRIBE results
23
+ for the column.
24
+
25
+ = Other Improvements
26
+
27
+ * When eager loading via the tactical_eager_loading plugin, objects
28
+ that already have an association loaded will not have it reloaded
29
+ unless the :eager_reload option is given.
30
+
31
+ * When cloning an association and using a different :class option
32
+ than the cloned association, the :class option given when cloning
33
+ will now take precedence over the :class option for the cloned
34
+ association.
35
+
36
+ * When using the mock postgres adapter, the adapter defaults to
37
+ supporting PostgreSQL 14 (previously, it defaulted to supporting
38
+ PostgreSQL 9.5).
39
+
40
+ * Sequel now avoids a method redefined warning in the lazy attributes
41
+ plugin in verbose warnings mode.
42
+
43
+ = Other
44
+
45
+ * Sequel's primary discussion forum is now GitHub Discussions. The
46
+ sequel-talk Google Group is still available for users who would
47
+ prefer to use that instead.
@@ -0,0 +1,87 @@
1
+ = New Features
2
+
3
+ * When the sql_comments Database extension is used,
4
+ Database#with_comments is now added, which can be used for including
5
+ comments for all queries executed inside a given block. This can
6
+ be useful if you want to analyze database query logs, and want to
7
+ group all related queries:
8
+
9
+ DB.with_comments(model: Album, action: :all) do
10
+ DB[:albums].all
11
+ # SELECT * FROM albums -- model:Album,action:all
12
+ end
13
+
14
+ * An sql_comments plugin has been added, which will automatically
15
+ add SQL comments for all queries generated by model class, instance
16
+ and dataset methods:
17
+
18
+ Album.plugin :sql_comments
19
+
20
+ album = Album[1]
21
+ # SELECT * FROM albums WHERE (id = 1) LIMIT 1
22
+ # -- model:Album,method_type:class,method:[]
23
+
24
+ album.update(:name=>'A')
25
+ # UPDATE albums SET name = 'baz' WHERE (id = 1)
26
+ # -- model:Album,method_type:instance,method:update
27
+
28
+ Album.where(id: 1).delete
29
+ # DELETE FROM albums WHERE (id = 1)
30
+ # -- model:Album,method_type:dataset,method:delete
31
+
32
+ This plugin requires you have loaded the sql_comments Database
33
+ extension into the related Database before use.
34
+
35
+ * A date_parse_input_handler extension has been added to support
36
+ custom handling of input to date parsing methods. Among other
37
+ things, you can use this to limit the length of strings that
38
+ will be parsed, which can prevent ArgumentErrors in newer Ruby
39
+ versions:
40
+
41
+ Sequel.extension :date_parse_input_handler
42
+ Sequel.date_parse_input_handler do |string|
43
+ string.b[0, 128]
44
+ end
45
+
46
+ = Other Improvements
47
+
48
+ * On Ruby 3.1, the core_refinements extension now avoids the
49
+ deprecated Refinement#include, switching to
50
+ Refinement#import_methods.
51
+
52
+ * On Ruby 3.1, the subclasses plugin will use Ruby's native support
53
+ for Class#subclasses.
54
+
55
+ * The subclasses plugin has renamed descendents to descendants and
56
+ freeze_descendents to freeze_descendants. The previous method
57
+ names are still available as aliases.
58
+
59
+ * The :ruby_default schema entry for datetime/timestamp columns now
60
+ respects Sequel.datetime_class. Previously, the value for the
61
+ :ruby_default schema entry would always be a DateTime value for
62
+ such columns.
63
+
64
+ * The pg_interval extension now works with ActiveSupport 7.0.
65
+
66
+ * The shared postgres adapter now respects
67
+ Database#default_string_column_size for setting the size of string
68
+ columns that don't use text as the database type.
69
+
70
+ * Database#supports_check_constraints? now returns true on MySQL
71
+ 8.0.19+. This fixes drop_constraint in certain cases when combining
72
+ the constraint dropping with other changes in the same alter_table
73
+ block.
74
+
75
+ * The mysql adapter now supports the ruby-mysql 3 API (ruby-mysql
76
+ is a pure-ruby MySQL driver).
77
+
78
+ * The mysql adapter no longer uses the connection's server_version
79
+ method if it is defined, as the method does not return the
80
+ correct value when using the ruby-mysql driver with MariaDB.
81
+
82
+ * Comments added by the sql_comments extension no longer modify
83
+ cached SQL for a dataset.
84
+
85
+ = Other
86
+
87
+ * This is Sequel's 250th release!
@@ -0,0 +1,23 @@
1
+ = Improvements
2
+
3
+ * The jdbc/h2 subadapter now supports H2 version 2.0. It continues to
4
+ support H2 versions 1.3 and 1.4.
5
+
6
+ * The mysql2 adapter's prepared statement support now reuses existing
7
+ native prepared statements, instead of only binding variables on
8
+ newly prepared statements. This was the intended behavior
9
+ previously, and should result in increased performance in cases
10
+ where preparing a query takes significant time.
11
+
12
+ * The subclasses plugin now ignores an existing Class#subclasses
13
+ method if it is defined in Ruby. This fixes cases where usage of
14
+ ActiveSupport would break the subclasses plugin.
15
+
16
+ * Database#call_sproc in the jdbc adapter will now always close the
17
+ prepared call it creates. Before, if there was an exception raised
18
+ when setting the arguments for the prepared call, the prepared call
19
+ would not be closed.
20
+
21
+ * A more appropriate error is now issued if you try to use the
22
+ column_encryption plugin to encrypt a column without setting up an
23
+ encryption key.