sequel 5.37.0 → 5.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +62 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/doc/cheat_sheet.rdoc +5 -5
  6. data/doc/code_order.rdoc +0 -12
  7. data/doc/fork_safety.rdoc +84 -0
  8. data/doc/opening_databases.rdoc +5 -1
  9. data/doc/postgresql.rdoc +1 -1
  10. data/doc/querying.rdoc +3 -3
  11. data/doc/release_notes/5.38.0.txt +28 -0
  12. data/doc/release_notes/5.39.0.txt +19 -0
  13. data/doc/release_notes/5.40.0.txt +40 -0
  14. data/doc/release_notes/5.41.0.txt +25 -0
  15. data/doc/release_notes/5.42.0.txt +136 -0
  16. data/doc/sql.rdoc +1 -1
  17. data/doc/testing.rdoc +2 -0
  18. data/lib/sequel/adapters/ado.rb +16 -16
  19. data/lib/sequel/adapters/jdbc.rb +15 -3
  20. data/lib/sequel/adapters/jdbc/mysql.rb +4 -4
  21. data/lib/sequel/adapters/shared/mssql.rb +21 -1
  22. data/lib/sequel/adapters/shared/oracle.rb +1 -1
  23. data/lib/sequel/adapters/shared/postgres.rb +6 -4
  24. data/lib/sequel/adapters/shared/sqlite.rb +35 -1
  25. data/lib/sequel/database/connecting.rb +0 -1
  26. data/lib/sequel/database/misc.rb +15 -2
  27. data/lib/sequel/database/schema_generator.rb +16 -1
  28. data/lib/sequel/database/schema_methods.rb +20 -6
  29. data/lib/sequel/database/transactions.rb +1 -1
  30. data/lib/sequel/dataset/features.rb +10 -0
  31. data/lib/sequel/dataset/prepared_statements.rb +2 -0
  32. data/lib/sequel/dataset/sql.rb +32 -10
  33. data/lib/sequel/extensions/async_thread_pool.rb +438 -0
  34. data/lib/sequel/extensions/blank.rb +8 -0
  35. data/lib/sequel/extensions/date_arithmetic.rb +8 -9
  36. data/lib/sequel/extensions/eval_inspect.rb +2 -0
  37. data/lib/sequel/extensions/inflector.rb +8 -0
  38. data/lib/sequel/extensions/migration.rb +2 -0
  39. data/lib/sequel/extensions/named_timezones.rb +5 -1
  40. data/lib/sequel/extensions/pg_array.rb +1 -0
  41. data/lib/sequel/extensions/pg_interval.rb +34 -8
  42. data/lib/sequel/extensions/pg_row.rb +1 -0
  43. data/lib/sequel/extensions/query.rb +2 -0
  44. data/lib/sequel/model/associations.rb +28 -4
  45. data/lib/sequel/model/base.rb +23 -6
  46. data/lib/sequel/model/plugins.rb +5 -0
  47. data/lib/sequel/plugins/association_proxies.rb +2 -0
  48. data/lib/sequel/plugins/async_thread_pool.rb +39 -0
  49. data/lib/sequel/plugins/auto_validations.rb +15 -1
  50. data/lib/sequel/plugins/class_table_inheritance.rb +0 -5
  51. data/lib/sequel/plugins/composition.rb +7 -2
  52. data/lib/sequel/plugins/constraint_validations.rb +2 -1
  53. data/lib/sequel/plugins/dataset_associations.rb +4 -1
  54. data/lib/sequel/plugins/dirty.rb +0 -1
  55. data/lib/sequel/plugins/json_serializer.rb +37 -22
  56. data/lib/sequel/plugins/nested_attributes.rb +8 -3
  57. data/lib/sequel/plugins/pg_array_associations.rb +4 -0
  58. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +2 -0
  59. data/lib/sequel/plugins/serialization.rb +2 -1
  60. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  61. data/lib/sequel/plugins/single_table_inheritance.rb +7 -0
  62. data/lib/sequel/plugins/tree.rb +9 -4
  63. data/lib/sequel/plugins/validation_helpers.rb +6 -2
  64. data/lib/sequel/timezones.rb +8 -3
  65. data/lib/sequel/version.rb +1 -1
  66. metadata +35 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8314ec290f56d764f7d072c3982407c7478c4f762248cee2243b74dc82a6a31
4
- data.tar.gz: 4df47669ee1ff9f2a93ad6aaca195f168a7fa61572fe77347af9959eea6e025a
3
+ metadata.gz: 41e987d42df8d1b3ab41dd6555b5e338b94ba0e2fcd11fa3db7f9b955920d533
4
+ data.tar.gz: fdcaed20caa20bbaffe5854cbcd6836787e92a2bbadb89373337602926d476ca
5
5
  SHA512:
6
- metadata.gz: 6b1d811a54e04b79b92c96a8a93f6d1b714dc15451790f4db6a8e0f7f133be1d7350fa46a30448445089aa5cada2c05270bc6382d36e89a6e2d1a9efd5ceec2c
7
- data.tar.gz: dce7a9c8cda4f7498de3af2fe999e8ed3b1566d7022b1274352ce397eca96c8b234dfe13549ed0e613e24effa3519b46cd3c037b7abe62ce84367396ce7f71c7
6
+ metadata.gz: c9a3927fe546ee7f91497e5bd50e9fa9241dd46aa7d3b3c331d10f8ac369eedd204a488207c509e909d9eb5d7deeeb13ab20888568f7e91f53fba526323df566
7
+ data.tar.gz: a9108c8ce0d78d93c94f0a947171687022dd20ee1305633533340f1cb1a71d012248f9a9bb72eb7af28cc258240ec2e8f090683d1ad7a68c33f69d261c684ea0
data/CHANGELOG CHANGED
@@ -1,3 +1,65 @@
1
+ === 5.42.0 (2021-03-01)
2
+
3
+ * Make the ado timestamp conversion proc a normal conversion proc that can be overridden similar to other conversion procs (jeremyevans)
4
+
5
+ * Add :reject_nil option to the nested_attributes method, to ignore calls where nil is passed as the associated object data (jeremyevans)
6
+
7
+ * Add async_thread_pool plugin for easier async usage with model classes and support for async destroy, with_pk, and with_pk! methods (jeremyevans)
8
+
9
+ * Add async_thread_pool Database extension for executing queries asynchronously using a thread pool (jeremyevans)
10
+
11
+ * Fix possible thread safety issue in Database#extension that could allow Module#extended to be called twice with the same Database instance (jeremyevans)
12
+
13
+ * Support cases where validations make modifications beyond setting errors in Model#freeze (jeremyevans)
14
+
15
+ * Add Model#to_json_data to the json_serializer plugin, returning a JSON data structure (jeremyevans)
16
+
17
+ === 5.41.0 (2021-02-01)
18
+
19
+ * Have explicit :text option for a String column take priority over :size option on PostgreSQL (jeremyevans) (#1750)
20
+
21
+ * Support a :skip_invalid option in auto_validations plugin for not adding errors to a column that already has an error (jeremyevans)
22
+
23
+ * Support a :skip_invalid option in validation_helpers for not adding an error to a column that already has an error (jeremyevans)
24
+
25
+ * Support :adder, :remover, and :clearer association options that use keyword arguments in Ruby 2.7+ (jeremyevans)
26
+
27
+ * Make pg_interval use the same number of seconds per year and per month as ActiveSupport::Duration when using ActiveSupport 5.1+ (jeremyevans)
28
+
29
+ === 5.40.0 (2021-01-01)
30
+
31
+ * Support UPDATE FROM syntax in SQLite 3.33.0+ (jeremyevans)
32
+
33
+ * Have pg_interval extension work with ActiveSupport 6.1 (jeremyevans)
34
+
35
+ * Have date_arithmetic extension work with ActiveSupport 6.1 (jeremyevans)
36
+
37
+ * Avoid method redefinition warnings in verbose warning mode (jeremyevans)
38
+
39
+ === 5.39.0 (2020-12-01)
40
+
41
+ * Support :clustered option for primary key and unique constraints on Microsoft SQL Server (jeremyevans)
42
+
43
+ * Do not modify the size of binary columns when using set_column_allow_null on Microsoft SQL Server (jeremyevans) (#1736)
44
+
45
+ * Add a fork safety guide with more detail on how to use Sequel with libraries that fork (janko) (#1733)
46
+
47
+ * Make the roots_dataset method in the tree plugin work with queries using joins (jeremyevans) (#1731)
48
+
49
+ * Make Database#tables return partitioned tables on PostgreSQL 10+ (epoberezhny) (#1729, #1730)
50
+
51
+ === 5.38.0 (2020-11-01)
52
+
53
+ * Do not add new Database instances to Sequel::DATABASES if the test connection fails (jeremyevans) (#1727)
54
+
55
+ * Support the newer com.mysql.cj.jdbc.Driver in the jdbc/mysql adapter (jeremyevans)
56
+
57
+ * Do not swallow disconnect errors in Database#create_or_replace_view or Database#create_table* on Oracle (jeremyevans)
58
+
59
+ * Only rescue non-disconnect Sequel::DatabaseErrors in Postgres::Database#server_version (jeremyevans) (#1724)
60
+
61
+ * Make the single_table_inheritance and prepared_statements plugins work if loaded into the same class (jeremyevans) (#1721)
62
+
1
63
  === 5.37.0 (2020-10-01)
2
64
 
3
65
  * Recognize more unsigned decimal/float types in the schema dumper (akimd, jeremyevans) (#1720)
data/MIT-LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2007-2008 Sharon Rosner
2
- Copyright (c) 2008-2020 Jeremy Evans
2
+ Copyright (c) 2008-2021 Jeremy Evans
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to
data/README.rdoc CHANGED
@@ -883,7 +883,7 @@ raise an error by default:
883
883
  == Sequel Release Policy
884
884
 
885
885
  New major versions of Sequel do not have a defined release policy, but historically have
886
- occurred once ever few years.
886
+ occurred once every few years.
887
887
 
888
888
  New minor versions of Sequel are released around once a month near the start of the month.
889
889
 
data/doc/cheat_sheet.rdoc CHANGED
@@ -95,18 +95,18 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
95
95
 
96
96
  === AND/OR/NOT
97
97
 
98
- DB[:items].where{(x > 5) & (y > 10)}.sql
98
+ DB[:items].where{(x > 5) & (y > 10)}
99
99
  # SELECT * FROM items WHERE ((x > 5) AND (y > 10))
100
100
 
101
- DB[:items].where(Sequel.or(x: 1, y: 2) & Sequel.~(z: 3)).sql
101
+ DB[:items].where(Sequel.or(x: 1, y: 2) & Sequel.~(z: 3))
102
102
  # SELECT * FROM items WHERE (((x = 1) OR (y = 2)) AND (z != 3))
103
103
 
104
104
  === Mathematical operators
105
105
 
106
- DB[:items].where{x + y > z}.sql
106
+ DB[:items].where{x + y > z}
107
107
  # SELECT * FROM items WHERE ((x + y) > z)
108
108
 
109
- DB[:items].where{price - 100 < avg(price)}.sql
109
+ DB[:items].where{price - 100 < avg(price)}
110
110
  # SELECT * FROM items WHERE ((price - 100) < avg(price))
111
111
 
112
112
  === Raw SQL Fragments
@@ -130,7 +130,7 @@ Without a filename argument, the sqlite adapter will setup a new sqlite database
130
130
 
131
131
  == Joins
132
132
 
133
- DB[:items].left_outer_join(:categories, id: :category_id).sql
133
+ DB[:items].left_outer_join(:categories, id: :category_id)
134
134
  # SELECT * FROM items
135
135
  # LEFT OUTER JOIN categories ON categories.id = items.category_id
136
136
 
data/doc/code_order.rdoc CHANGED
@@ -100,15 +100,3 @@ and freezing them can easily be achieved through the plugin:
100
100
  # ... setup models
101
101
  # Now finalize associations & freeze models by calling the plugin:
102
102
  Sequel::Model.freeze_descendents
103
-
104
- == Disconnect If Using Forking Webserver with Code Preloading
105
-
106
- If you are using a forking webserver such as unicorn or passenger, with
107
- a feature that loads your Sequel code before forking connections (code
108
- preloading), then you must disconnect your database connections before
109
- forking. If you don't do this, you can end up with child processes
110
- sharing database connections and all sorts of weird behavior. Sequel
111
- will automatically reconnect on an as needed basis in the child
112
- processes, so you only need to do the following in the parent process:
113
-
114
- DB.disconnect
@@ -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
@@ -208,7 +208,7 @@ Example connection strings:
208
208
 
209
209
  jdbc:sqlite::memory:
210
210
  jdbc:postgresql://localhost/database?user=username
211
- jdbc:mysql://localhost/test?user=root&password=root
211
+ jdbc:mysql://localhost/test?user=root&password=root&serverTimezone=UTC
212
212
  jdbc:h2:mem:
213
213
  jdbc:hsqldb:mem:mymemdb
214
214
  jdbc:derby:memory:myDb;create=true
@@ -240,6 +240,10 @@ The following additional options are supported:
240
240
  There are a few issues with specific jdbc driver gems:
241
241
 
242
242
  jdbc-h2 :: jdbc-h2 versions greater than 1.3.175 have issues with ORDER BY not working correctly in some cases.
243
+ jdbc-mysql :: Depending on the configuration of the MySQL server, jdbc-mysql versions greater 8 may complain
244
+ about the server time zone being unrecognized. You can either use an older jdbc-mysql version,
245
+ or you can specify the +serverTimezone+ option in the connection string, as shown in the example
246
+ jdbc:mysql connection string above.
243
247
 
244
248
  === mysql
245
249
 
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)
data/doc/querying.rdoc CHANGED
@@ -746,7 +746,7 @@ shortcuts for all common (and most uncommon) join types. For example
746
746
 
747
747
  Album.join(:artists, id: :artist_id)
748
748
  # SELECT * FROM albums
749
- # INNER JOIN artists ON (artists.id = albums.artist_id))))
749
+ # INNER JOIN artists ON (artists.id = albums.artist_id)
750
750
 
751
751
  And +left_join+ does a LEFT JOIN:
752
752
 
@@ -870,14 +870,14 @@ In this case, you don't even need to specify any conditions.
870
870
  ==== Join Blocks
871
871
 
872
872
  You can provide a block to any of the join methods that accept
873
- conditions. This block should accept 3 arguments, the table alias
873
+ conditions. This block should accept 3 arguments: the table alias
874
874
  for the table currently being joined, the table alias for the last
875
875
  table joined (or first table), and an array of previous
876
876
  <tt>Sequel::SQL::JoinClause</tt>s.
877
877
 
878
878
  This allows you to qualify columns similar to how the implicit
879
879
  qualification works, without worrying about the specific aliases
880
- being used. For example, lets say you wanted to join the albums
880
+ being used. For example, let's say you wanted to join the albums
881
881
  and artists tables, but only want albums where the artist's name
882
882
  comes before the album's name.
883
883
 
@@ -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.
@@ -0,0 +1,136 @@
1
+ = New Features
2
+
3
+ * An async_thread_pool Database extension has been added, which
4
+ executes queries and processes results using a separate thread
5
+ pool. This allows you do do things like:
6
+
7
+ foos = DB[:foos].async.all
8
+ bars = DB[:bars].async.select_map(:name)
9
+ foo_bars = DB[:foo_bars].async.each{|x| p x}
10
+
11
+ and have the three method calls (all, select_map, and each)
12
+ execute concurrently. On Ruby implementations without a global
13
+ VM lock, such as JRuby, it will allow for parallel execution of
14
+ the method calls. On CRuby, the main benefit will be for cases
15
+ where query execution takes a long time or there is significant
16
+ latency between the application and the database.
17
+
18
+ When you call a method on foos, bars, or foo_bars, if the thread
19
+ pool hasn't finished processing the method, the calling code will
20
+ block until the method call has finished.
21
+
22
+ By default, for consistency, calling code will not preempt the
23
+ async thread pool. For example, if you do:
24
+
25
+ DB[:foos].async.all.size
26
+
27
+ The calling code will always wait for the async thread pool to
28
+ run the all method, and then the calling code will call size on
29
+ the result. This ensures that async queries will not use the
30
+ same connection as the the calling thread, even if calling thread
31
+ has a connection checked out.
32
+
33
+ In some cases, such as when the async thread pool is very busy,
34
+ preemption is desired for performance reasons. If you set the
35
+ :preempt_async_thread Database option before loading the
36
+ async_thread_pool extension, preemption will be allowed. With
37
+ preemption allowed, if the async thread pool has not started the
38
+ processing of the method at the time the calling code needs the
39
+ results of the method, the calling code will preempt the async
40
+ thread pool, and run the method on the current thread.
41
+
42
+ By default, the async thread pool uses the same number of threads as
43
+ the Database objects :max_connections attribute (the default for
44
+ that is 4). You can modify the number of async threads by setting
45
+ the :num_async_threads Database option before loading the Database
46
+ async_thread_pool extension.
47
+
48
+ Most Dataset methods that execute queries on the database and return
49
+ results will operate asynchronously if the the dataset is set to be
50
+ asynchronous via the Dataset#async method. This includes most
51
+ methods available due to the inclusion in Enumerable, even if not
52
+ defined by Dataset itself.
53
+
54
+ There are multiple caveats when using the async_thread_pool
55
+ extension:
56
+
57
+ * Asynchronous behavior is harder to understand and harder to
58
+ debug. It would be wise to only use this support in cases where
59
+ it provides is significant performance benefit.
60
+
61
+ * Dataset methods executed asynchronously will use a separate
62
+ database connection than the calling thread, so they will not
63
+ respect transactions in the calling thread, or other cases where
64
+ the calling thread checks out a connection directly using
65
+ Database#synchronize. They will also not respect the use of
66
+ Database#with_server (from the server_block extension) in the
67
+ calling thread.
68
+
69
+ * Dataset methods executed asynchronously should never ignore their
70
+ return value. Code such as:
71
+
72
+ DB[:table].async.insert(1)
73
+
74
+ is probablematic because without storing the return value, you
75
+ have no way to block until the insert has been completed.
76
+
77
+ * The returned object for Dataset methods executed asynchronously is
78
+ a proxy object (promise). So you should never do:
79
+
80
+ row = DB[:table].async.first
81
+ # ...
82
+ if row
83
+ end
84
+
85
+ # or:
86
+
87
+ bool = DB[:table].async.get(:boolean_column)
88
+ # ...
89
+ if bool
90
+ end
91
+
92
+ because the if branches will always be taken as row and bool will
93
+ never be nil or false. If you want to get the underlying value,
94
+ call itself on the proxy object (or __value if using Ruby <2.2).
95
+
96
+ For the same reason, you should not use the proxy objects directly
97
+ in case expressions or as arguments to Class#===. Use itself or
98
+ __value in those cases.
99
+
100
+ * Dataset methods executed asynchronously that include blocks have the
101
+ block executed asynchronously as well, assuming that the method
102
+ calls the block. Because these blocks are executed in a separate
103
+ thread, you cannot use control flow modifiers such as break or
104
+ return in them.
105
+
106
+ * An async_thread_pool model plugin has been added. This requires the
107
+ async_thread_pool extension has been loaded into the model's Database
108
+ object, and allows you to call Model.async instead of
109
+ Model.dataset.async. It also adds async support to the destroy,
110
+ with_pk, and with_pk! model dataset methods.
111
+
112
+ * Model#to_json_data has been added to the json_serializer plugin, for
113
+ returning a hash of data that can be converted to JSON, instead of
114
+ a JSON string.
115
+
116
+ * A :reject_nil option has been added to the nested_attributes method
117
+ in the nested_attributes plugin. This will ignore calls to the
118
+ nested attributes setter method where nil is passed as the setter
119
+ method argument.
120
+
121
+ = Other Improvements
122
+
123
+ * Model#freeze now works in case where model validation modifies the
124
+ object beyond adding errors.
125
+
126
+ * Model#freeze in the composition, serialization, and
127
+ serialization_modification_detection plugins now works in cases
128
+ where validation would end up loading the composed or
129
+ serialized values.
130
+
131
+ * Database#extension now avoids a possible thread safety issue that
132
+ could result in the extension being loaded into the Database twice.
133
+
134
+ * The ado adapter now supports overriding the timestamp conversion
135
+ proc. Previously, unlike other conversion procs, the timestamp
136
+ conversion proc was hard coded and could not be overridden.