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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 929f5047395464d1d3616aeab41742b6766ae14b96ca1f5b7ac47bb1991f3391
4
- data.tar.gz: c931c23d71b73ce2bb35118e1d02ecc2df529f2c297b995c9c5ee46c5b0bfe85
3
+ metadata.gz: 6cbc8358a3097618cd7acc4e8cf46c013ef4d8b6aefde8e05de0277ca585c0b9
4
+ data.tar.gz: 2ba345ca95455c1acaabf7e2619b81b97b332d1c353bab2de50f700e9ba69148
5
5
  SHA512:
6
- metadata.gz: 062f919b4268a57e392bad5dd7d4a988adc90a8df2d4076f5abfa9afe7c125534f9e7ad1ca16733d0539e622f2b988f95d4653d6b076cd356809d95daf1c24d2
7
- data.tar.gz: 1f1efabd6b3ae74c6d35b3d0a23ad87a9d1c939e209afc2f24267840c6c72b2ff60fb1ca86010335b65a251c3c57fa81b300aa4cf38b9ad49df53b00f931d89f
6
+ metadata.gz: a9d3f729bfa2e5a82e78521856b2928887700a67129e47af6eb40d1bf4508b6deb7202928f7626ea3c4f6a424b23df8410756d2333295c1d56fee79b123dc7dd
7
+ data.tar.gz: 6184d4e1dd21bc550ac99285fd379215dcd13b4474aeff39928bdc68cc25ac34b235f68bed03260fae3fea34ef203422e2665bb12c822479e6ce4cc8d54d1f59
@@ -1,3 +1,7 @@
1
+ ## 1.0.1 (2020-10-28)
2
+
3
+ * Use Active Record connection lock in `Database#synchronize` (@janko)
4
+
1
5
  ## 1.0.0 (2020-10-25)
2
6
 
3
7
  * Clear AR statement cache on `ActiveRecord::PreparedStatementCacheExpired` when Sequel holds the transaction (@janko)
data/README.md CHANGED
@@ -1,25 +1,23 @@
1
- # Sequel::ActiveRecordConnection
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. It works on ActiveRecord 4.2
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
- Note that this is a best-effort implementation, so some discrepancies are still
14
- possible. That being said, this implementation passes Rodauth's test suite
15
- (for all adapters), which has some fairly advanced Sequel usage.
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
- ```ruby
22
- gem "sequel-activerecord_connection", "~> 0.3"
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
- yield activerecord_connection.raw_connection
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.0.0"
3
+ spec.version = "1.0.1"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
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.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-25 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel