mysql_framework 2.1.3 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e1cae192a6864318bec19e54ce0bc4db409f393493884dd7455be0809ac8bc0
|
4
|
+
data.tar.gz: d8ab5dfaf00a88efc3addb04e66c84bc8a614a9f827651a4b37581a3a71936f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97152eedd702ad53bc27655e47eab758cd53f1e01fc756f493ebfba8e8bb618a99307c7c717d40ea4aaf331c8c5d16d5ec45dc3dc4fc36391beec50dad8a1cbe
|
7
|
+
data.tar.gz: 555e02b1f2f0a6eabb07a07a4651c39f7c1d400b843f2e21a3e6ee8e3268d4319e682c7702d0e5a2fe12ffd0e8b344ff8ab5b39adfbd7d1c60c150d385ba4fc6
|
@@ -4,6 +4,7 @@ module MysqlFramework
|
|
4
4
|
class Connector
|
5
5
|
def initialize(options = {})
|
6
6
|
@options = default_options.merge(options)
|
7
|
+
@mutex = Mutex.new
|
7
8
|
|
8
9
|
Mysql2::Client.default_query_options.merge!(symbolize_keys: true, cast_booleans: true)
|
9
10
|
end
|
@@ -25,7 +26,7 @@ module MysqlFramework
|
|
25
26
|
|
26
27
|
until @connection_pool.empty?
|
27
28
|
conn = @connection_pool.pop(true)
|
28
|
-
conn
|
29
|
+
conn&.close
|
29
30
|
end
|
30
31
|
|
31
32
|
@connection_pool = nil
|
@@ -38,31 +39,37 @@ module MysqlFramework
|
|
38
39
|
|
39
40
|
# This method is called to fetch a client from the connection pool.
|
40
41
|
def check_out
|
41
|
-
|
42
|
+
@mutex.synchronize do
|
43
|
+
begin
|
44
|
+
return new_client unless connection_pool_enabled?
|
42
45
|
|
43
|
-
|
46
|
+
client = @connection_pool.pop(true)
|
44
47
|
|
45
|
-
|
48
|
+
client.ping if @options[:reconnect]
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
client
|
51
|
+
rescue ThreadError
|
52
|
+
if @created_connections < max_pool_size
|
53
|
+
client = new_client
|
54
|
+
@created_connections += 1
|
55
|
+
return client
|
56
|
+
end
|
54
57
|
|
55
|
-
|
58
|
+
MysqlFramework.logger.error { "[#{self.class}] - Database connection pool depleted." }
|
56
59
|
|
57
|
-
|
60
|
+
raise 'Database connection pool depleted.'
|
61
|
+
end
|
62
|
+
end
|
58
63
|
end
|
59
64
|
|
60
65
|
# This method is called to check a client back in to the connection when no longer needed.
|
61
66
|
def check_in(client)
|
62
|
-
|
67
|
+
@mutex.synchronize do
|
68
|
+
return client&.close unless connection_pool_enabled?
|
63
69
|
|
64
|
-
|
65
|
-
|
70
|
+
client = new_client if client&.closed?
|
71
|
+
@connection_pool.push(client)
|
72
|
+
end
|
66
73
|
end
|
67
74
|
|
68
75
|
# This method is called to use a client from the connection pool.
|
@@ -44,10 +44,10 @@ module MysqlFramework
|
|
44
44
|
|
45
45
|
def index_exists?(client, table_name, index_name)
|
46
46
|
result = client.query(<<~SQL)
|
47
|
-
SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}"
|
47
|
+
SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}";
|
48
48
|
SQL
|
49
49
|
|
50
|
-
result.count
|
50
|
+
result.count >= 1
|
51
51
|
end
|
52
52
|
|
53
53
|
protected
|
@@ -118,6 +118,12 @@ describe MysqlFramework::Connector do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
describe '#check_out' do
|
121
|
+
it 'calls synchronize on the mutex' do
|
122
|
+
expect(subject.instance_variable_get(:@mutex)).to receive(:synchronize)
|
123
|
+
|
124
|
+
subject.check_out
|
125
|
+
end
|
126
|
+
|
121
127
|
context 'when connection pooling is enabled' do
|
122
128
|
context 'when there are available connections' do
|
123
129
|
before do
|
@@ -203,6 +209,12 @@ describe MysqlFramework::Connector do
|
|
203
209
|
end
|
204
210
|
|
205
211
|
describe '#check_in' do
|
212
|
+
it 'calls synchronize on the mutex' do
|
213
|
+
expect(subject.instance_variable_get(:@mutex)).to receive(:synchronize)
|
214
|
+
|
215
|
+
subject.check_out
|
216
|
+
end
|
217
|
+
|
206
218
|
context 'when connection pooling is enabled' do
|
207
219
|
it 'returns the provided client to the connection pool' do
|
208
220
|
expect(subject.connections).to receive(:push).with(client)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
140
|
+
rubygems_version: 3.3.5
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: A lightweight framework to provide managers for working with MySQL.
|