sequel 5.33.0 → 5.58.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +318 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +40 -9
  5. data/doc/association_basics.rdoc +77 -13
  6. data/doc/cheat_sheet.rdoc +13 -5
  7. data/doc/code_order.rdoc +0 -12
  8. data/doc/dataset_filtering.rdoc +2 -2
  9. data/doc/fork_safety.rdoc +84 -0
  10. data/doc/migration.rdoc +12 -6
  11. data/doc/model_plugins.rdoc +1 -1
  12. data/doc/opening_databases.rdoc +15 -3
  13. data/doc/postgresql.rdoc +9 -1
  14. data/doc/querying.rdoc +7 -5
  15. data/doc/release_notes/5.34.0.txt +40 -0
  16. data/doc/release_notes/5.35.0.txt +56 -0
  17. data/doc/release_notes/5.36.0.txt +60 -0
  18. data/doc/release_notes/5.37.0.txt +30 -0
  19. data/doc/release_notes/5.38.0.txt +28 -0
  20. data/doc/release_notes/5.39.0.txt +19 -0
  21. data/doc/release_notes/5.40.0.txt +40 -0
  22. data/doc/release_notes/5.41.0.txt +25 -0
  23. data/doc/release_notes/5.42.0.txt +136 -0
  24. data/doc/release_notes/5.43.0.txt +98 -0
  25. data/doc/release_notes/5.44.0.txt +32 -0
  26. data/doc/release_notes/5.45.0.txt +34 -0
  27. data/doc/release_notes/5.46.0.txt +87 -0
  28. data/doc/release_notes/5.47.0.txt +59 -0
  29. data/doc/release_notes/5.48.0.txt +14 -0
  30. data/doc/release_notes/5.49.0.txt +59 -0
  31. data/doc/release_notes/5.50.0.txt +78 -0
  32. data/doc/release_notes/5.51.0.txt +47 -0
  33. data/doc/release_notes/5.52.0.txt +87 -0
  34. data/doc/release_notes/5.53.0.txt +23 -0
  35. data/doc/release_notes/5.54.0.txt +27 -0
  36. data/doc/release_notes/5.55.0.txt +21 -0
  37. data/doc/release_notes/5.56.0.txt +51 -0
  38. data/doc/release_notes/5.57.0.txt +23 -0
  39. data/doc/release_notes/5.58.0.txt +31 -0
  40. data/doc/sql.rdoc +14 -2
  41. data/doc/testing.rdoc +10 -1
  42. data/doc/transactions.rdoc +0 -8
  43. data/doc/validations.rdoc +1 -1
  44. data/doc/virtual_rows.rdoc +1 -1
  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/mysql.rb +4 -4
  53. data/lib/sequel/adapters/jdbc/postgresql.rb +4 -4
  54. data/lib/sequel/adapters/jdbc.rb +29 -19
  55. data/lib/sequel/adapters/mysql.rb +80 -67
  56. data/lib/sequel/adapters/mysql2.rb +54 -49
  57. data/lib/sequel/adapters/odbc.rb +8 -6
  58. data/lib/sequel/adapters/oracle.rb +5 -4
  59. data/lib/sequel/adapters/postgres.rb +27 -29
  60. data/lib/sequel/adapters/shared/access.rb +2 -0
  61. data/lib/sequel/adapters/shared/db2.rb +30 -0
  62. data/lib/sequel/adapters/shared/mssql.rb +84 -7
  63. data/lib/sequel/adapters/shared/mysql.rb +33 -2
  64. data/lib/sequel/adapters/shared/oracle.rb +82 -7
  65. data/lib/sequel/adapters/shared/postgres.rb +158 -20
  66. data/lib/sequel/adapters/shared/sqlanywhere.rb +3 -0
  67. data/lib/sequel/adapters/shared/sqlite.rb +102 -10
  68. data/lib/sequel/adapters/sqlanywhere.rb +1 -1
  69. data/lib/sequel/adapters/sqlite.rb +60 -18
  70. data/lib/sequel/adapters/tinytds.rb +2 -1
  71. data/lib/sequel/adapters/utils/columns_limit_1.rb +22 -0
  72. data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -1
  73. data/lib/sequel/ast_transformer.rb +6 -0
  74. data/lib/sequel/connection_pool/sharded_single.rb +9 -8
  75. data/lib/sequel/connection_pool/sharded_threaded.rb +10 -10
  76. data/lib/sequel/connection_pool/single.rb +7 -9
  77. data/lib/sequel/connection_pool/threaded.rb +1 -1
  78. data/lib/sequel/core.rb +33 -24
  79. data/lib/sequel/database/connecting.rb +3 -4
  80. data/lib/sequel/database/misc.rb +37 -12
  81. data/lib/sequel/database/query.rb +3 -1
  82. data/lib/sequel/database/schema_generator.rb +50 -53
  83. data/lib/sequel/database/schema_methods.rb +45 -23
  84. data/lib/sequel/database/transactions.rb +9 -6
  85. data/lib/sequel/dataset/actions.rb +61 -8
  86. data/lib/sequel/dataset/features.rb +15 -0
  87. data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
  88. data/lib/sequel/dataset/prepared_statements.rb +2 -0
  89. data/lib/sequel/dataset/query.rb +114 -11
  90. data/lib/sequel/dataset/sql.rb +172 -46
  91. data/lib/sequel/deprecated.rb +3 -1
  92. data/lib/sequel/exceptions.rb +2 -0
  93. data/lib/sequel/extensions/_pretty_table.rb +1 -2
  94. data/lib/sequel/extensions/any_not_empty.rb +1 -1
  95. data/lib/sequel/extensions/async_thread_pool.rb +438 -0
  96. data/lib/sequel/extensions/blank.rb +8 -0
  97. data/lib/sequel/extensions/columns_introspection.rb +1 -2
  98. data/lib/sequel/extensions/core_refinements.rb +38 -11
  99. data/lib/sequel/extensions/date_arithmetic.rb +36 -24
  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 +3 -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 +139 -0
  106. data/lib/sequel/extensions/migration.rb +13 -2
  107. data/lib/sequel/extensions/named_timezones.rb +5 -1
  108. data/lib/sequel/extensions/pagination.rb +1 -1
  109. data/lib/sequel/extensions/pg_array.rb +1 -0
  110. data/lib/sequel/extensions/pg_array_ops.rb +6 -2
  111. data/lib/sequel/extensions/pg_enum.rb +3 -1
  112. data/lib/sequel/extensions/pg_extended_date_support.rb +2 -2
  113. data/lib/sequel/extensions/pg_hstore.rb +1 -1
  114. data/lib/sequel/extensions/pg_hstore_ops.rb +55 -3
  115. data/lib/sequel/extensions/pg_inet.rb +2 -0
  116. data/lib/sequel/extensions/pg_inet_ops.rb +1 -1
  117. data/lib/sequel/extensions/pg_interval.rb +35 -8
  118. data/lib/sequel/extensions/pg_json.rb +3 -5
  119. data/lib/sequel/extensions/pg_json_ops.rb +119 -4
  120. data/lib/sequel/extensions/pg_loose_count.rb +3 -1
  121. data/lib/sequel/extensions/pg_multirange.rb +372 -0
  122. data/lib/sequel/extensions/pg_range.rb +7 -19
  123. data/lib/sequel/extensions/pg_range_ops.rb +39 -9
  124. data/lib/sequel/extensions/pg_row.rb +1 -1
  125. data/lib/sequel/extensions/pg_row_ops.rb +25 -1
  126. data/lib/sequel/extensions/query.rb +3 -0
  127. data/lib/sequel/extensions/run_transaction_hooks.rb +1 -1
  128. data/lib/sequel/extensions/s.rb +4 -1
  129. data/lib/sequel/extensions/schema_dumper.rb +16 -5
  130. data/lib/sequel/extensions/server_block.rb +8 -12
  131. data/lib/sequel/extensions/sql_comments.rb +110 -3
  132. data/lib/sequel/extensions/sql_log_normalizer.rb +108 -0
  133. data/lib/sequel/extensions/sqlite_json_ops.rb +255 -0
  134. data/lib/sequel/extensions/string_agg.rb +1 -1
  135. data/lib/sequel/extensions/string_date_time.rb +19 -23
  136. data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
  137. data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
  138. data/lib/sequel/extensions/to_dot.rb +9 -3
  139. data/lib/sequel/model/associations.rb +342 -114
  140. data/lib/sequel/model/base.rb +45 -24
  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 +8 -3
  144. data/lib/sequel/model.rb +3 -1
  145. data/lib/sequel/plugins/association_pks.rb +60 -18
  146. data/lib/sequel/plugins/association_proxies.rb +3 -0
  147. data/lib/sequel/plugins/async_thread_pool.rb +39 -0
  148. data/lib/sequel/plugins/auto_restrict_eager_graph.rb +62 -0
  149. data/lib/sequel/plugins/auto_validations.rb +39 -5
  150. data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
  151. data/lib/sequel/plugins/blacklist_security.rb +1 -2
  152. data/lib/sequel/plugins/class_table_inheritance.rb +3 -8
  153. data/lib/sequel/plugins/column_encryption.rb +728 -0
  154. data/lib/sequel/plugins/composition.rb +8 -2
  155. data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
  156. data/lib/sequel/plugins/constraint_validations.rb +2 -1
  157. data/lib/sequel/plugins/csv_serializer.rb +2 -0
  158. data/lib/sequel/plugins/dataset_associations.rb +4 -1
  159. data/lib/sequel/plugins/dirty.rb +44 -0
  160. data/lib/sequel/plugins/enum.rb +124 -0
  161. data/lib/sequel/plugins/forbid_lazy_load.rb +2 -0
  162. data/lib/sequel/plugins/insert_conflict.rb +4 -0
  163. data/lib/sequel/plugins/instance_specific_default.rb +113 -0
  164. data/lib/sequel/plugins/json_serializer.rb +39 -24
  165. data/lib/sequel/plugins/lazy_attributes.rb +4 -1
  166. data/lib/sequel/plugins/many_through_many.rb +108 -9
  167. data/lib/sequel/plugins/nested_attributes.rb +8 -3
  168. data/lib/sequel/plugins/pg_array_associations.rb +58 -41
  169. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +2 -0
  170. data/lib/sequel/plugins/prepared_statements.rb +15 -12
  171. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
  172. data/lib/sequel/plugins/rcte_tree.rb +37 -35
  173. data/lib/sequel/plugins/serialization.rb +9 -3
  174. data/lib/sequel/plugins/serialization_modification_detection.rb +2 -1
  175. data/lib/sequel/plugins/single_table_inheritance.rb +7 -0
  176. data/lib/sequel/plugins/sql_comments.rb +189 -0
  177. data/lib/sequel/plugins/static_cache.rb +1 -1
  178. data/lib/sequel/plugins/string_stripper.rb +1 -1
  179. data/lib/sequel/plugins/subclasses.rb +28 -11
  180. data/lib/sequel/plugins/tactical_eager_loading.rb +8 -2
  181. data/lib/sequel/plugins/timestamps.rb +1 -1
  182. data/lib/sequel/plugins/tree.rb +9 -4
  183. data/lib/sequel/plugins/unused_associations.rb +521 -0
  184. data/lib/sequel/plugins/update_or_create.rb +1 -1
  185. data/lib/sequel/plugins/validation_class_methods.rb +5 -1
  186. data/lib/sequel/plugins/validation_helpers.rb +18 -11
  187. data/lib/sequel/plugins/xml_serializer.rb +1 -1
  188. data/lib/sequel/sql.rb +1 -1
  189. data/lib/sequel/timezones.rb +20 -17
  190. data/lib/sequel/version.rb +1 -1
  191. metadata +93 -39
@@ -36,8 +36,8 @@ Ranges (both inclusive and exclusive) can also be used:
36
36
 
37
37
  If you need to select multiple items from a dataset, you can supply an array:
38
38
 
39
- items.where(id: [1, 38, 47, 99]).sql
40
- # "SELECT * FROM items WHERE (id IN (1, 38, 47, 99))"
39
+ items.where(id: [1, 38, 47, 99]).sql
40
+ # "SELECT * FROM items WHERE (id IN (1, 38, 47, 99))"
41
41
 
42
42
  == Filtering using expressions
43
43
 
@@ -0,0 +1,84 @@
1
+ = Fork Safety
2
+
3
+ If you are forking or using a library that forks after you have created a
4
+ Sequel::Database instance, then you must disconnect database connections before forking. If you
5
+ don't do this, you can end up with child processes sharing database connections
6
+ and all sorts of weird behavior, including crashes. Sequel will automatically create new
7
+ connections on an as needed basis in the child processes, so you only need to do the following in
8
+ the parent process:
9
+
10
+ DB.disconnect
11
+
12
+ Or if you have connections to multiple databases:
13
+
14
+ Sequel::DATABASES.each(&:disconnect)
15
+
16
+ == Puma
17
+
18
+ When using the Puma web server in clustered mode (which is the default behavior in Puma 5+ when
19
+ using multiple processes), you should disconnect inside the +before_fork+ hook in your
20
+ Puma config:
21
+
22
+ before_fork do
23
+ Sequel::DATABASES.each(&:disconnect)
24
+ end
25
+
26
+ == Unicorn
27
+
28
+ When using the Unicorn web server and preloading the application (+preload_app true+ in the Unicorn
29
+ config), you should disconnect inside the +before_fork+ hook in the Unicorn config:
30
+
31
+ before_fork do
32
+ Sequel::DATABASES.each(&:disconnect)
33
+ end
34
+
35
+ == Passenger
36
+
37
+ In Passenger web server, you should disconnect inside the
38
+ +starting_worker_process+ event hook:
39
+
40
+ if defined?(PhusionPassenger)
41
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
42
+ Sequel::DATABASES.each(&:disconnect) if forked
43
+ end
44
+ end
45
+
46
+ Note that this disconnects after forking instead of before forking. Passenger does not
47
+ offer a before fork hook.
48
+
49
+ == Spring
50
+
51
+ In Spring application preloader, you should disconnect inside the +after_fork+ hook:
52
+
53
+ if defined?(Spring)
54
+ Spring.after_fork do
55
+ Sequel::DATABASES.each(&:disconnect)
56
+ end
57
+ end
58
+
59
+ As the method indicates, this disconnects after forking instead of before forking.
60
+ Spring does not offer a before fork hook.
61
+
62
+ == Resque
63
+
64
+ In Resque, you should disconnect inside the +before_fork+ hook:
65
+
66
+ Resque.before_fork do |job|
67
+ Sequel::DATABASES.each(&:disconnect)
68
+ end
69
+
70
+ == Parallel
71
+
72
+ If you're using the Parallel gem with processes, you should disconnect before
73
+ calling it:
74
+
75
+ Sequel::DATABASES.each(&:disconnect)
76
+ Parallel.map(['a','b','c'], in_processes: 3) { |one_letter| }
77
+
78
+ == Other Libraries Calling fork
79
+
80
+ For any other library that calls fork, you should disconnect before calling
81
+ a method that forks:
82
+
83
+ Sequel::DATABASES.each(&:disconnect)
84
+ SomeLibrary.method_that_forks
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
@@ -212,7 +212,7 @@ In general you should only require plugin arguments if you absolutely must have
212
212
 
213
213
  == Handling Subclasses
214
214
 
215
- Sequel::Model uses a copy-on-subclassing approach to model state. So instead of model subclasses asking their parent class for a value if they don't have it defined, the value is automatically copied from the parent class to the subclass when the subclass is created. While you can do this by overriding the inherited class method, there is a available shortcut that handles most cases:
215
+ Sequel::Model uses a copy-on-subclassing approach to model state. So instead of having a model subclass ask its superclass for a value if the subclass don't have the value defined, the value should be copied from the parent class to the subclass when the subclass is created. While this can be implemented by overriding the +inherited+ class method, there is an available shortcut that handles most cases:
216
216
 
217
217
  module Sequel::Plugins::Foo
218
218
  module ClassMethods
@@ -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
@@ -208,7 +209,7 @@ Example connection strings:
208
209
 
209
210
  jdbc:sqlite::memory:
210
211
  jdbc:postgresql://localhost/database?user=username
211
- jdbc:mysql://localhost/test?user=root&password=root
212
+ jdbc:mysql://localhost/test?user=root&password=root&serverTimezone=UTC
212
213
  jdbc:h2:mem:
213
214
  jdbc:hsqldb:mem:mymemdb
214
215
  jdbc:derby:memory:myDb;create=true
@@ -240,12 +241,16 @@ The following additional options are supported:
240
241
  There are a few issues with specific jdbc driver gems:
241
242
 
242
243
  jdbc-h2 :: jdbc-h2 versions greater than 1.3.175 have issues with ORDER BY not working correctly in some cases.
244
+ jdbc-mysql :: Depending on the configuration of the MySQL server, jdbc-mysql versions greater 8 may complain
245
+ about the server time zone being unrecognized. You can either use an older jdbc-mysql version,
246
+ or you can specify the +serverTimezone+ option in the connection string, as shown in the example
247
+ jdbc:mysql connection string above.
243
248
 
244
249
  === mysql
245
250
 
246
251
  Requires: mysql
247
252
 
248
- 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).
249
254
 
250
255
  The following additional options are supported:
251
256
 
@@ -254,6 +259,8 @@ The following additional options are supported:
254
259
  :compress :: Whether to compress data sent/received via the socket connection.
255
260
  :config_default_group :: The default group to read from the in the MySQL config file, defaults to "client")
256
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.
257
264
  :encoding :: Specify the encoding/character set to use for the connection.
258
265
  :fractional_seconds :: On MySQL 5.6.5+, this option is recognized and will include fractional seconds in
259
266
  time/timestamp values, as well as have the schema method create columns that can contain
@@ -274,7 +281,9 @@ if either the :sslca or :sslkey option is given.
274
281
 
275
282
  This is a newer MySQL adapter that does typecasting in C, so it is often faster than the
276
283
  mysql adapter. The options given are passed to Mysql2::Client.new, see the mysql2 documentation
277
- 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).
278
287
 
279
288
  === odbc
280
289
 
@@ -379,6 +388,9 @@ The following additional options are supported:
379
388
 
380
389
  :readonly :: open database in read-only mode
381
390
  :timeout :: the busy timeout to use in milliseconds (default: 5000).
391
+ :setup_regexp_function :: Whether to setup a REGEXP function in the underlying SQLite3::Database object. Doing so
392
+ allows you to use regexp support in dataset expressions. Note that this creates a new
393
+ Regexp object per call to the function, so it is not an efficient implementation.
382
394
 
383
395
  Note that SQLite memory databases are restricted to a single connection by
384
396
  default. This is because SQLite does not allow multiple connections to
data/doc/postgresql.rdoc CHANGED
@@ -213,7 +213,7 @@ other tables. Support may be added in the future.
213
213
  === Creating Unlogged Tables
214
214
 
215
215
  PostgreSQL allows users to create unlogged tables, which are faster but not crash safe. Sequel
216
- allows you do create an unlogged table by specifying the <tt>unlogged: true</tt> option to +create_table+:
216
+ allows you to create an unlogged table by specifying the <tt>unlogged: true</tt> option to +create_table+:
217
217
 
218
218
  DB.create_table(:table, unlogged: true){Integer :i}
219
219
  # CREATE UNLOGGED TABLE "table" ("i" integer)
@@ -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
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
 
@@ -746,7 +748,7 @@ shortcuts for all common (and most uncommon) join types. For example
746
748
 
747
749
  Album.join(:artists, id: :artist_id)
748
750
  # SELECT * FROM albums
749
- # INNER JOIN artists ON (artists.id = albums.artist_id))))
751
+ # INNER JOIN artists ON (artists.id = albums.artist_id)
750
752
 
751
753
  And +left_join+ does a LEFT JOIN:
752
754
 
@@ -870,14 +872,14 @@ In this case, you don't even need to specify any conditions.
870
872
  ==== Join Blocks
871
873
 
872
874
  You can provide a block to any of the join methods that accept
873
- conditions. This block should accept 3 arguments, the table alias
875
+ conditions. This block should accept 3 arguments: the table alias
874
876
  for the table currently being joined, the table alias for the last
875
877
  table joined (or first table), and an array of previous
876
878
  <tt>Sequel::SQL::JoinClause</tt>s.
877
879
 
878
880
  This allows you to qualify columns similar to how the implicit
879
881
  qualification works, without worrying about the specific aliases
880
- being used. For example, lets say you wanted to join the albums
882
+ being used. For example, let's say you wanted to join the albums
881
883
  and artists tables, but only want albums where the artist's name
882
884
  comes before the album's name.
883
885
 
@@ -0,0 +1,40 @@
1
+ = New Features
2
+
3
+ * The association_pks plugin now creates *_pks_dataset methods for
4
+ each association. These are similar to the existing *_pks getter
5
+ methods, but they return a dataset of the keys instead of the keys
6
+ themselves.
7
+
8
+ * The association_pks plugin now supports a :cache_pks association
9
+ option, which will cache calls to the *_pks getter method. The
10
+ default behavior remains that the *_pks getter method only returns
11
+ cached values if the *_pks= setter method has been used to set the
12
+ values.
13
+
14
+ * The *_pks getter methods supported by the association_pks plugin
15
+ now support a :refresh option to ignore any cached values, similar
16
+ to how the association getter methods work.
17
+
18
+ = Other Improvements
19
+
20
+ * If trying to disconnect a server that doesn't exist when using a
21
+ sharded connection pool, a Sequel::Error is now raised. Previously,
22
+ the sharded threaded pool raised a NoMethodError and the sharded
23
+ single connection pool did not raise an error.
24
+
25
+ * If using the :savepoint option when savepoints are not supported,
26
+ a Sequel::InvalidOperation exception is now raised, instead of a
27
+ NoMethodError.
28
+
29
+ * Calling Dataset#eager_graph with no arguments now returns the
30
+ dataset.
31
+
32
+ * If not connected to the database, the single connection pool will
33
+ not yield any connections to Database#pool.all_connections.
34
+
35
+ * Forcing a :ruby eager limit strategy for an association without a
36
+ limit or offset now works correctly.
37
+
38
+ * Multiple unnecessary conditionals have been removed.
39
+
40
+ * Sequel core and model code now have 100% branch coverage.
@@ -0,0 +1,56 @@
1
+ = New Features
2
+
3
+ * An instance_specific_default plugin has been added for setting the
4
+ default for the :instance_specific association option, or
5
+ warning/raises in cases where it is not specified. This allows
6
+ you to easily find associations that would be considering instance
7
+ specific by default, and mark them as not instance specific for
8
+ better performance.
9
+
10
+ = Other Improvements
11
+
12
+ * Setting the :instance_specific association option to false now
13
+ works correctly if the association uses a block. Associations
14
+ that set the :dataset option are now always considered instance
15
+ specific, even if the :instance_specific option is explicitly
16
+ passed.
17
+
18
+ * The validation_class_methods plugin now considers all :if,
19
+ :allow_missing, :allow_nil, and :allow_blank options. Previously,
20
+ it only considered the first of those options that was set.
21
+
22
+ * Model.finalize_associations no longer breaks if you have
23
+ instance-specific associations.
24
+
25
+ * Model.plugin now warns if you load the plugin with arguments or a
26
+ block if the plugin does not accept arguments or block. This is
27
+ because a future change to Sequel could break the call.
28
+
29
+ * When emulating unsupported alter table operations on SQLite, Sequel
30
+ now copies composite unique constraints unless the alter table
31
+ operation is the dropping of a unique constraint.
32
+
33
+ * Sequel now recognizes an additional disconnect error in the oracle
34
+ adapter.
35
+
36
+ * In the run_transaction_hooks extension, calling
37
+ run_after_{commit,rollback}_hooks now raises the correct exception
38
+ class.
39
+
40
+ * In the pg_range extension, conversion procs for the tsrange[] and
41
+ tstzrange[] types are not added unless the Database uses the
42
+ pg_array extension.
43
+
44
+ * Multiple unnecessary conditionals in plugins and extensions have
45
+ been removed.
46
+
47
+ * Sequel plugin and extension code now have 100% branch coverage.
48
+
49
+ * Sequel now avoids a statement not reached verbose warning in
50
+ Dataset#clone.
51
+
52
+ = Backwards Compatibility
53
+
54
+ * The output of Dataset#to_dot in the to_dot extension has changed
55
+ slightly, including hash entries with nil keys. These entries
56
+ were previously ignored.
@@ -0,0 +1,60 @@
1
+ = New Features
2
+
3
+ * Dataset#with_ties has been added on PostgreSQL 13+ and Microsoft
4
+ SQL Server, which will have a limited dataset also return all
5
+ rows with the same order as the final row.
6
+
7
+ * In the pg_json_ops extension, the following methods have been
8
+ added to Postgres::JSONBOp, all of which require PostgreSQL 13+:
9
+
10
+ * #set_lax
11
+ * #path_exists_tz!
12
+ * #path_match_tz!
13
+ * #path_query_tz
14
+ * #path_query_array_tz
15
+ * #path_query_first_tz
16
+
17
+ * On Oracle, the Database#view_exists? method now accepts a
18
+ :current_schema option to limit the views returned to the
19
+ current schema, instead of all non-system schemas.
20
+
21
+ = Other Improvements
22
+
23
+ * Sequel will now pass keyword arguments through in the following
24
+ cases:
25
+
26
+ * When loading plugins (Model.plugin)
27
+
28
+ * Class methods automically defined for methods defined in a
29
+ Model.dataset_module block
30
+
31
+ * Methods defined by Plugins.def_dataset_method
32
+
33
+ * Database methods called inside migrations
34
+
35
+ * Methods called via an association proxy when using the
36
+ association_proxies plugin.
37
+
38
+ * Dataset methods called inside a Dataset#query block when using
39
+ the query extension.
40
+
41
+ Previously, keywords were not handled in these cases, which would
42
+ cause deprecation warnings in Ruby 2.7 and ArgumentErrors in Ruby
43
+ 3.0. Note that Sequel itself does not use keyword arguments at
44
+ all, so all of these changes only affect cases where external
45
+ methods are defined that accept keywords, and Sequel methods are
46
+ called with keywords that end up being delegated to the external
47
+ methods.
48
+
49
+ * The odbc adapter will now stream result sets instead of loading
50
+ the entire result set in memory and then iterating over it.
51
+
52
+ * Sequel now recognizes another disconnect error in the mysql and
53
+ mysql2 adapters.
54
+
55
+ = Backwards Compatibility
56
+
57
+ * Due to the odbc adapter change to use streaming, issuing queries
58
+ inside a Dataset#each block will no longer work unless a different
59
+ shard or thread is used. The behavior of such code is considered
60
+ undefined on all Sequel adapters.
@@ -0,0 +1,30 @@
1
+ = New Features
2
+
3
+ * Model#column_previously_was and #column_previously_changed? have
4
+ been added to the dirty plugin, for getting the previous values
5
+ of the column before saving and for whether there were changes
6
+ before saving.
7
+
8
+ Model#column_previously_changed? accepts :from and :to options
9
+ to allow you to more easily determine if the value changed from
10
+ and/or to specific values.
11
+
12
+ This information was previously obtainable via
13
+ Model#previous_changes, but these new methods offer a friendlier
14
+ interface.
15
+
16
+ * Postgres::PGRow::{Array,Hash}Row#op has been added to the
17
+ pg_row_ops extension if the pg_row extension is loaded. This
18
+ is similar to how the pg_array_ops, pg_hstore_ops, and
19
+ pg_json_ops and #op method to their objects. This makes it
20
+ easier to perform row operations on literal rows.
21
+
22
+ = Other Improvements
23
+
24
+ * The schema_dumper extension now supports more unsigned numeric
25
+ types, such as "decimal(7,2) unsigned" and "real unsigned".
26
+
27
+ * IntegerMigrator now raises an Migrator::Error if attempting to
28
+ migrate down when there are migration files missing and needed for
29
+ the down migration. Previously, IntegerMigrator would not raise an
30
+ exception and would make no database changes in this case.
@@ -0,0 +1,28 @@
1
+ = New Features
2
+
3
+ * The jdbc/mysql adapter now supports the newer
4
+ com.mysql.cj.jdbc.Driver driver. The adapter will still attempt to
5
+ load the older com.mysql.jdbc.Driver if the com.mysql.cj.jdbc.Driver
6
+ is not found.
7
+
8
+ = Other Improvements
9
+
10
+ * When testing a connection after creating a new Database instance
11
+ raises an exception, the Database instance is removed from
12
+ Sequel::DATABASES.
13
+
14
+ * The single_table_inheritance and prepared_statements plugins now
15
+ work correctly if loaded into the same class.
16
+
17
+ * Database connect and disconnect errors are no longer swallowed when
18
+ calling Database#create_or_replace_view, Database#server_version
19
+ on PostgreSQL, or Database#create_table* on Oracle.
20
+
21
+ = Backwards Compatibility
22
+
23
+ * Previously, instantiating a new Database instance directly using
24
+ Sequel::Database.new did not test the connection by default. That
25
+ was instead handled by Sequel::Database.connect. The test
26
+ connection now happens inside Database#initialize. This should only
27
+ affect backwards compatibility for code that is calling
28
+ Sequel::Database.new directly.
@@ -0,0 +1,19 @@
1
+ = New Features
2
+
3
+ * On Microsoft SQL Server, the :clustered option is now supported
4
+ for primary key and unique constraints. You can use a true value
5
+ for CLUSTERED and a false value for NONCLUSTERED.
6
+
7
+ = Other Improvements
8
+
9
+ * Partitioned tables are now included in the result of
10
+ Database#tables on PostgreSQL.
11
+
12
+ * alter_table set_column_allow_null no longer drops the size of
13
+ binary columns on Microsoft SQL Server.
14
+
15
+ * In the tree plugin, the roots_dataset method now works correctly
16
+ with queries using joins by qualifying the parent column.
17
+
18
+ * A fork safety guide has been added, discussing fork safety issues
19
+ when using Sequel.
@@ -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.