umbrellio-sequel-plugins 0.13.0.172 → 0.13.0.185

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5176b7fbd45ffbe7f5bd111f6e82d379cd040e37b1d140c19586bfdccc60c20
4
- data.tar.gz: 2ddf58eef5a8a9fc17342f411f693cc39bc0bda944b943294f09737fc828c6d1
3
+ metadata.gz: 2e73343a56718daadf888b113d611970815cd0061776219e1d119cfedd899a0a
4
+ data.tar.gz: 80b5c588f80b8ffdc7cb72e4f53551db1e63833e50158a0370927b92b535aa41
5
5
  SHA512:
6
- metadata.gz: 7565d2fb5b73ce545046672a10cda09368428093d05576173f6bac0df707256e38f23b56dfa1885b639eb9a41e40236c829eb4efadcc2771a6a8563cf0f7b9a4
7
- data.tar.gz: 15646f89fb545c3b901e8f93dfb5e08a5e7092286342223dc2e81b3803cc01f673b7dff741fcd33df89e63ddb61b44469cf448bff04f52150e2585b942e30906
6
+ metadata.gz: ce4bb7cd35a3c372738cffea7320cc87b70cb5228b3b9f372d126dab7ea5be0878c8d27a02d7f662b310766b141887831bc4c2da5d561900c9eae2625a3dc2ab
7
+ data.tar.gz: 39c5ddb279c2985caa8dec93bd9ac92c4ffbb68f49d184eacfa7ad0f8a23e3012ee4828ae9609965d5d10fb4a2aaf695c65094867d6265b6bc8e23eb70c955ec
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
+ gem "async", "1.31.0" # TODO: Remove version binding after Ruby 2.7 and 3.0 support drop.
7
8
  gem "money"
8
9
  gem "pg"
9
10
  gem "pry"
data/Gemfile.lock CHANGED
@@ -14,10 +14,19 @@ GEM
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
16
  ast (2.4.2)
17
+ async (1.31.0)
18
+ console (~> 1.10)
19
+ nio4r (~> 2.3)
20
+ timers (~> 4.1)
17
21
  coderay (1.1.3)
18
22
  concurrent-ruby (1.2.2)
23
+ console (1.17.2)
24
+ fiber-annotation
25
+ fiber-local
19
26
  diff-lcs (1.5.0)
20
27
  docile (1.4.0)
28
+ fiber-annotation (0.2.0)
29
+ fiber-local (1.0.0)
21
30
  i18n (1.14.1)
22
31
  concurrent-ruby (~> 1.0)
23
32
  json (2.6.3)
@@ -25,6 +34,7 @@ GEM
25
34
  minitest (5.18.1)
26
35
  money (6.16.0)
27
36
  i18n (>= 0.6.4, <= 2)
37
+ nio4r (2.5.9)
28
38
  parallel (1.23.0)
29
39
  parser (3.2.2.3)
30
40
  ast (~> 2.4.1)
@@ -48,7 +58,7 @@ GEM
48
58
  rspec-expectations (3.12.3)
49
59
  diff-lcs (>= 1.2.0, < 2.0)
50
60
  rspec-support (~> 3.12.0)
51
- rspec-mocks (3.12.5)
61
+ rspec-mocks (3.12.6)
52
62
  diff-lcs (>= 1.2.0, < 2.0)
53
63
  rspec-support (~> 3.12.0)
54
64
  rspec-support (3.12.1)
@@ -97,6 +107,7 @@ GEM
97
107
  simplecov-lcov (0.8.0)
98
108
  simplecov_json_formatter (0.1.4)
99
109
  symbiont-ruby (0.7.0)
110
+ timers (4.3.5)
100
111
  tzinfo (2.0.6)
101
112
  concurrent-ruby (~> 1.0)
102
113
  unicode-display_width (2.4.2)
@@ -105,6 +116,7 @@ PLATFORMS
105
116
  ruby
106
117
 
107
118
  DEPENDENCIES
119
+ async (= 1.31.0)
108
120
  money
109
121
  pg
110
122
  pry
data/README.md CHANGED
@@ -17,29 +17,30 @@ $ bundle
17
17
 
18
18
  # Extensions
19
19
 
20
- - [`CurrencyRates`](#CurrencyRates)
21
- - [`PGTools`](#PGTools)
22
- - [`Slave`](#Slave)
23
- - [`Synchronize`](#Synchronize)
24
- - [`Methods in Migrations`](#Methods-in-Migrations)
25
- - [`Deferrable Foreign Keys`](#Deferrable-Foreign-Keys)
26
- - [`Set Local`](#Set-Local)
27
- - [`Migration Transaction Options`](#Migration-Transaction-Options)
20
+ - [`CurrencyRates`](#currencyrates)
21
+ - [`PGTools`](#pgtools)
22
+ - [`Slave`](#slave)
23
+ - [`Synchronize`](#synchronize)
24
+ - [`Methods in Migrations`](#methods-in-migrations)
25
+ - [`Deferrable Foreign Keys`](#deferrable-foreign-keys)
26
+ - [`Set Local`](#set-local)
27
+ - [`Migration Transaction Options`](#migration-transaction-options)
28
+ - [`Fibered Connection Pool`](#fibered-connection-pool)
28
29
 
29
30
  # Plugins
30
31
 
31
- - [`AttrEncrypted`](#AttrEncrypted)
32
- - [`Duplicate`](#Duplicate)
33
- - [`GetColumnValue`](#GetColumnValue)
34
- - [`MoneyAccessors`](#MoneyAccessors)
35
- - [`StoreAccessors`](#StoreAccessors)
36
- - [`Synchronize`](#Synchronize)
37
- - [`Upsert`](#Upsert)
38
- - [`WithLock`](#WithLock)
32
+ - [`AttrEncrypted`](#attrencrypted)
33
+ - [`Duplicate`](#duplicate)
34
+ - [`GetColumnValue`](#getcolumnvalue)
35
+ - [`MoneyAccessors`](#moneyaccessors)
36
+ - [`StoreAccessors`](#storeaccessors)
37
+ - [`Synchronize`](#synchronize)
38
+ - [`Upsert`](#upsert)
39
+ - [`WithLock`](#withlock)
39
40
 
40
41
  # Tools
41
- - [`TimestampMigratorUndoExtension`](#TimestampMigratorUndoExtension)
42
- - [`Rails DBConsole`](#Rails-DBConsole)
42
+ - [`TimestampMigratorUndoExtension`](#timestampmigratorundoextension)
43
+ - [`Rails DBConsole`](#rails-dbconsole)
43
44
 
44
45
  ## CurrencyRates
45
46
 
@@ -248,6 +249,29 @@ SELECT '1';
248
249
  ROLLBACK;
249
250
  ```
250
251
 
252
+ ## Fibered Connection Pool
253
+
254
+ Sequel connection pool for fiber powered web servers or applications
255
+ (e.g. [falcon](https://github.com/socketry/falcon), [async](https://github.com/socketry/async))
256
+
257
+ Runtime dependency: [async](https://github.com/socketry/async)
258
+
259
+ You need to make sure that command `require "async"` works for your project.
260
+
261
+ The main difference from default `Sequel::ThreadedConnectionPool` that you can skip max_connections
262
+ configuration to produce as much connection as your application neeeded.
263
+
264
+ Also there is no any thead-safe code with synchronize and etc. So this connection pool works much
265
+ faster.
266
+
267
+ Enable:
268
+
269
+ Put this code before your application connects to database
270
+ ```ruby
271
+ Sequel.extension(:fiber_concurrency) # Default Sequel extension for fiber isolation level
272
+ Sequel.extension(:fibered_connection_pool)
273
+ ```
274
+
251
275
  ## AttrEncrypted
252
276
 
253
277
  Enable: `Sequel::Model.plugin :attr_encrypted`
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "async"
4
+ require "async/notification"
5
+
6
+ class Sequel::FiberedConnectionPool < Sequel::ConnectionPool
7
+ def initialize(db, opts = Sequel::OPTS)
8
+ super(db, opts)
9
+
10
+ @max_connections = opts[:max_connections]
11
+ @available_connections = []
12
+ @notification = Async::Notification.new
13
+ @size = 0
14
+ end
15
+
16
+ def hold(*)
17
+ connection = wait_for_connection
18
+ return connection unless block_given?
19
+
20
+ begin
21
+ yield connection
22
+ rescue Sequel::DatabaseDisconnectError, *@error_classes => error
23
+ if disconnect_error?(error)
24
+ disconnect_connection(connection)
25
+ connection = nil
26
+ @size -= 1
27
+ end
28
+ raise
29
+ ensure
30
+ if connection
31
+ @available_connections.push(connection)
32
+ @notification.signal if Async::Task.current?
33
+ end
34
+ end
35
+ end
36
+
37
+ def disconnect(*)
38
+ @available_connections.each(&:close)
39
+ @available_connections.clear
40
+
41
+ @size = 0
42
+ end
43
+
44
+ def size
45
+ @size
46
+ end
47
+
48
+ private
49
+
50
+ def wait_for_connection
51
+ until (connection = find_or_create_connection)
52
+ @notification.wait
53
+ end
54
+
55
+ connection
56
+ end
57
+
58
+ def find_or_create_connection
59
+ if (connection = @available_connections.shift)
60
+ return connection
61
+ end
62
+
63
+ if @max_connections.nil? || @size < @max_connections
64
+ connection = make_new(:default)
65
+ @size += 1
66
+
67
+ return connection
68
+ end
69
+
70
+ nil
71
+ end
72
+ end
73
+
74
+ module Sequel::ConnectionPoolPatch
75
+ def connection_pool_class(*)
76
+ Sequel.current.is_a?(Fiber) ? Sequel::FiberedConnectionPool : super
77
+ end
78
+ end
79
+
80
+ # NOTE: Ruby 2.7 DOES NOT SUPPORT class methods prepend in this way
81
+ # https://bugs.ruby-lang.org/issues/17423
82
+ if RUBY_VERSION > "3"
83
+ Sequel::ConnectionPool::ClassMethods.prepend(Sequel::ConnectionPoolPatch)
84
+ else
85
+ class Sequel::ConnectionPool
86
+ class << self
87
+ prepend Sequel::ConnectionPoolPatch
88
+ end
89
+ end
90
+ end
data/utils/database.rb CHANGED
@@ -18,6 +18,7 @@ DB.extension :set_local
18
18
  DB.extension :synchronize
19
19
 
20
20
  Sequel.extension :deferrable_foreign_keys
21
+ Sequel.extension :fibered_connection_pool
21
22
  Sequel.extension :migration
22
23
  Sequel.extension :pg_array_ops
23
24
  Sequel.extension :pg_json_ops
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umbrellio-sequel-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0.172
4
+ version: 0.13.0.185
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Umbrellio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-12 00:00:00.000000000 Z
11
+ date: 2023-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -59,6 +59,7 @@ files:
59
59
  - bin/setup
60
60
  - lib/sequel/extensions/currency_rates.rb
61
61
  - lib/sequel/extensions/deferrable_foreign_keys.rb
62
+ - lib/sequel/extensions/fibered_connection_pool.rb
62
63
  - lib/sequel/extensions/methods_in_migrations.rb
63
64
  - lib/sequel/extensions/migration_transaction_options.rb
64
65
  - lib/sequel/extensions/pg_tools.rb