sequel-activerecord_connection 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -9
- data/lib/sequel/extensions/activerecord_connection.rb +16 -1
- data/sequel-activerecord_connection.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cbc8358a3097618cd7acc4e8cf46c013ef4d8b6aefde8e05de0277ca585c0b9
|
4
|
+
data.tar.gz: 2ba345ca95455c1acaabf7e2619b81b97b332d1c353bab2de50f700e9ba69148
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9d3f729bfa2e5a82e78521856b2928887700a67129e47af6eb40d1bf4508b6deb7202928f7626ea3c4f6a424b23df8410756d2333295c1d56fee79b123dc7dd
|
7
|
+
data.tar.gz: 6184d4e1dd21bc550ac99285fd379215dcd13b4474aeff39928bdc68cc25ac34b235f68bed03260fae3fea34ef203422e2665bb12c822479e6ce4cc8d54d1f59
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,25 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# sequel-activerecord_connection
|
2
2
|
|
3
3
|
This is an extension for [Sequel] that allows it to reuse an existing
|
4
|
-
ActiveRecord connection for database interaction.
|
5
|
-
or higher, and supports the built-in `postgresql`, `mysql2` and `sqlite3`
|
6
|
-
adapters, as well as JDBC adapter for JRuby.
|
4
|
+
ActiveRecord connection for database interaction.
|
7
5
|
|
8
6
|
This can be useful if you're using a library that uses Sequel for database
|
9
7
|
interaction (e.g. [Rodauth]), but you want to avoid creating a separate
|
10
8
|
database connection. Or if you're transitioning from ActiveRecord to Sequel,
|
11
9
|
and want the database connection to be shared.
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
It works on ActiveRecord 4.2+ and fully supports PostgresSQL, MySQL and SQLite
|
12
|
+
adapters, both the native ones and JDBC (JRuby). Other adapters might work too,
|
13
|
+
but their integration hasn't been tested.
|
16
14
|
|
17
15
|
## Installation
|
18
16
|
|
19
17
|
Add this line to your application's Gemfile:
|
20
18
|
|
21
|
-
```
|
22
|
-
gem "sequel-activerecord_connection", "~> 0
|
19
|
+
```rb
|
20
|
+
gem "sequel-activerecord_connection", "~> 1.0"
|
23
21
|
```
|
24
22
|
|
25
23
|
And then execute:
|
@@ -31,7 +31,9 @@ module Sequel
|
|
31
31
|
|
32
32
|
# Avoid calling Sequel's connection pool, instead use Active Record's.
|
33
33
|
def synchronize(*)
|
34
|
-
|
34
|
+
activerecord_lock do
|
35
|
+
yield activerecord_connection.raw_connection
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
# Log executed queries into Active Record logger as well.
|
@@ -111,6 +113,19 @@ module Sequel
|
|
111
113
|
super
|
112
114
|
end
|
113
115
|
|
116
|
+
# Active Record doesn't guarantee that a single connection can only be used
|
117
|
+
# by one thread at a time, so we need to use locking, which is what Active
|
118
|
+
# Record does internally as well.
|
119
|
+
def activerecord_lock
|
120
|
+
return yield if ActiveRecord.version < Gem::Version.new("5.1.0")
|
121
|
+
|
122
|
+
activerecord_connection.lock.synchronize do
|
123
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
124
|
+
yield
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
114
129
|
def activerecord_connection
|
115
130
|
activerecord_model.connection
|
116
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-activerecord_connection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|