sequel 5.38.0 → 5.43.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +54 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/doc/cheat_sheet.rdoc +5 -5
- data/doc/code_order.rdoc +0 -12
- data/doc/fork_safety.rdoc +84 -0
- data/doc/postgresql.rdoc +1 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/5.39.0.txt +19 -0
- data/doc/release_notes/5.40.0.txt +40 -0
- data/doc/release_notes/5.41.0.txt +25 -0
- data/doc/release_notes/5.42.0.txt +136 -0
- data/doc/release_notes/5.43.0.txt +98 -0
- data/doc/sql.rdoc +1 -1
- data/doc/testing.rdoc +2 -0
- data/lib/sequel/adapters/ado.rb +16 -16
- data/lib/sequel/adapters/jdbc.rb +2 -2
- data/lib/sequel/adapters/shared/mssql.rb +21 -1
- data/lib/sequel/adapters/shared/postgres.rb +5 -3
- data/lib/sequel/adapters/shared/sqlite.rb +35 -1
- data/lib/sequel/database/misc.rb +1 -2
- data/lib/sequel/database/schema_generator.rb +16 -1
- data/lib/sequel/database/schema_methods.rb +19 -5
- data/lib/sequel/database/transactions.rb +1 -1
- data/lib/sequel/dataset/features.rb +10 -0
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/sql.rb +32 -10
- data/lib/sequel/extensions/async_thread_pool.rb +438 -0
- data/lib/sequel/extensions/blank.rb +8 -0
- data/lib/sequel/extensions/date_arithmetic.rb +7 -9
- data/lib/sequel/extensions/eval_inspect.rb +2 -0
- data/lib/sequel/extensions/inflector.rb +8 -0
- data/lib/sequel/extensions/migration.rb +2 -0
- data/lib/sequel/extensions/named_timezones.rb +5 -1
- data/lib/sequel/extensions/pg_array.rb +1 -0
- data/lib/sequel/extensions/pg_interval.rb +34 -8
- data/lib/sequel/extensions/pg_row.rb +1 -0
- data/lib/sequel/extensions/query.rb +2 -0
- data/lib/sequel/model/associations.rb +28 -4
- data/lib/sequel/model/base.rb +23 -6
- data/lib/sequel/model/plugins.rb +5 -0
- data/lib/sequel/plugins/association_proxies.rb +2 -0
- data/lib/sequel/plugins/async_thread_pool.rb +39 -0
- data/lib/sequel/plugins/auto_validations.rb +15 -1
- data/lib/sequel/plugins/column_encryption.rb +711 -0
- data/lib/sequel/plugins/composition.rb +7 -2
- data/lib/sequel/plugins/constraint_validations.rb +2 -1
- data/lib/sequel/plugins/dataset_associations.rb +4 -1
- data/lib/sequel/plugins/json_serializer.rb +37 -22
- data/lib/sequel/plugins/nested_attributes.rb +8 -3
- data/lib/sequel/plugins/pg_array_associations.rb +4 -0
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +2 -0
- data/lib/sequel/plugins/serialization.rb +8 -3
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +2 -0
- data/lib/sequel/plugins/tree.rb +9 -4
- data/lib/sequel/plugins/validation_helpers.rb +6 -2
- data/lib/sequel/timezones.rb +8 -3
- data/lib/sequel/version.rb +1 -1
- metadata +36 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69c695b559f3d5c19284905e8bad5a8775cced221f5cd3f5bb1d89daa9c0785c
|
4
|
+
data.tar.gz: 03cd2d01139038c3e6d1e1232f6b48a104657391aeefd82feab2636044480eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b6f0b096657603c11cf54b1b15b660c5b85a697e8b31b69f97f33d579401a73915a315b771467e56159313243c5643bb3ca5fd8c208f2c443d8c7536cba9fc0
|
7
|
+
data.tar.gz: 1a44276ab427bc2f9a82e2f651950100360df998af75a9d3ca08618acfa3778b02764f544738569c5947b350ac8b2485b825052869ac882728707014e90633a8
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,57 @@
|
|
1
|
+
=== 5.43.0 (2021-04-01)
|
2
|
+
|
3
|
+
* Add column_encryption plugin, for encrypting column values (jeremyevans)
|
4
|
+
|
5
|
+
=== 5.42.0 (2021-03-01)
|
6
|
+
|
7
|
+
* Make the ado timestamp conversion proc a normal conversion proc that can be overridden similar to other conversion procs (jeremyevans)
|
8
|
+
|
9
|
+
* Add :reject_nil option to the nested_attributes method, to ignore calls where nil is passed as the associated object data (jeremyevans)
|
10
|
+
|
11
|
+
* Add async_thread_pool plugin for easier async usage with model classes and support for async destroy, with_pk, and with_pk! methods (jeremyevans)
|
12
|
+
|
13
|
+
* Add async_thread_pool Database extension for executing queries asynchronously using a thread pool (jeremyevans)
|
14
|
+
|
15
|
+
* Fix possible thread safety issue in Database#extension that could allow Module#extended to be called twice with the same Database instance (jeremyevans)
|
16
|
+
|
17
|
+
* Support cases where validations make modifications beyond setting errors in Model#freeze (jeremyevans)
|
18
|
+
|
19
|
+
* Add Model#to_json_data to the json_serializer plugin, returning a JSON data structure (jeremyevans)
|
20
|
+
|
21
|
+
=== 5.41.0 (2021-02-01)
|
22
|
+
|
23
|
+
* Have explicit :text option for a String column take priority over :size option on PostgreSQL (jeremyevans) (#1750)
|
24
|
+
|
25
|
+
* Support a :skip_invalid option in auto_validations plugin for not adding errors to a column that already has an error (jeremyevans)
|
26
|
+
|
27
|
+
* Support a :skip_invalid option in validation_helpers for not adding an error to a column that already has an error (jeremyevans)
|
28
|
+
|
29
|
+
* Support :adder, :remover, and :clearer association options that use keyword arguments in Ruby 2.7+ (jeremyevans)
|
30
|
+
|
31
|
+
* Make pg_interval use the same number of seconds per year and per month as ActiveSupport::Duration when using ActiveSupport 5.1+ (jeremyevans)
|
32
|
+
|
33
|
+
=== 5.40.0 (2021-01-01)
|
34
|
+
|
35
|
+
* Support UPDATE FROM syntax in SQLite 3.33.0+ (jeremyevans)
|
36
|
+
|
37
|
+
* Have pg_interval extension work with ActiveSupport 6.1 (jeremyevans)
|
38
|
+
|
39
|
+
* Have date_arithmetic extension work with ActiveSupport 6.1 (jeremyevans)
|
40
|
+
|
41
|
+
* Avoid method redefinition warnings in verbose warning mode (jeremyevans)
|
42
|
+
|
43
|
+
=== 5.39.0 (2020-12-01)
|
44
|
+
|
45
|
+
* Support :clustered option for primary key and unique constraints on Microsoft SQL Server (jeremyevans)
|
46
|
+
|
47
|
+
* Do not modify the size of binary columns when using set_column_allow_null on Microsoft SQL Server (jeremyevans) (#1736)
|
48
|
+
|
49
|
+
* Add a fork safety guide with more detail on how to use Sequel with libraries that fork (janko) (#1733)
|
50
|
+
|
51
|
+
* Make the roots_dataset method in the tree plugin work with queries using joins (jeremyevans) (#1731)
|
52
|
+
|
53
|
+
* Make Database#tables return partitioned tables on PostgreSQL 10+ (epoberezhny) (#1729, #1730)
|
54
|
+
|
1
55
|
=== 5.38.0 (2020-11-01)
|
2
56
|
|
3
57
|
* Do not add new Database instances to Sequel::DATABASES if the test connection fails (jeremyevans) (#1727)
|
data/MIT-LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright (c) 2007-2008 Sharon Rosner
|
2
|
-
Copyright (c) 2008-
|
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
|
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)}
|
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))
|
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}
|
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)}
|
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)
|
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
|
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
|
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
|
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,
|
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,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.
|