sequel-activerecord_connection 1.2.5 → 1.2.8

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: 2f7764c3c949cc68b34a38607264efa44915adcecca59514e5ecfda075f9e9d7
4
- data.tar.gz: 273b77e0d95f1506765bd4ee88d79ec69639224b7d220b6d368d62bdfc7b665b
3
+ metadata.gz: 5b1082cb22dfbf8b9bac60130ae0c37454433f3693fb8ddcb65b5c4acf947c66
4
+ data.tar.gz: 5bd9aeb196b39ac626e087f88442f42318b628e0d6890761fa071f69efb4b403
5
5
  SHA512:
6
- metadata.gz: d32c90dbfc833db0c8f62ee72ef7a2d997e9c3d0b5e9f7e0dc817431a9e96cbb1e87542de0c828742a8068cfa5227ae8cf287931c6bcb05b6da87fd87b00c924
7
- data.tar.gz: 174b89d5a19094c68549fb1112df0de767eb9ed77b1acd7e17114ac3af3637f47f95c46c3e98dace8b28123a473669ff17b04197ee3819c4a92a78cfa6f3a024
6
+ metadata.gz: d9dd1bc2f3b5e2435e8bf5786955cf6c53ebe26d30d87a283b571fa3c2cb5ad1cef61b99997b3dc480d123636920681a7304d7e3a1a05f7d59cadf6ac56f9334
7
+ data.tar.gz: 4ce05904e61edb1a245ccdec85aa5bbc21c40af2b7c67d0d877c36d2f40bb9430e3b5a76c7a4f4b183d8a544f97b0fc132653d2d03623fef949fb7eb01beb783
data/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
- ## HEAD
1
+ ## 1.2.8 (2022-02-28)
2
+
3
+ * Support the pg_streaming database extension from the sequel_pg gem (@janko)
4
+
5
+ ## 1.2.7 (2022-01-20)
6
+
7
+ * Require Sequel 3.38+ (@janko)
8
+
9
+ ## 1.2.6 (2021-12-26)
10
+
11
+ * Speed up connection access by avoiding checking Active Record version at runtime (@janko)
12
+
13
+ ## 1.2.5 (2021-12-19)
2
14
 
3
15
  * Loosen Active Record dependency to allow any 7.x version (@janko)
4
16
 
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Janko Marohnić
3
+ Copyright (c) 2020-2022 Janko Marohnić
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,18 +1,42 @@
1
1
  # sequel-activerecord_connection
2
2
 
3
- This is an extension for [Sequel] that allows it to reuse an existing
4
- ActiveRecord connection for database interaction.
3
+ This is a database extension for [Sequel] that makes it to reuse an existing
4
+ Active Record connection for database interaction.
5
5
 
6
- This can be useful if you're using a library that uses Sequel for database
7
- interaction (e.g. [Rodauth] or [rom-sql]), but you want to avoid creating a
8
- separate database connection. Or if you're transitioning from ActiveRecord to
9
- Sequel, and want the database connection to be shared.
6
+ This can be useful if you want to use a library that uses Sequel (e.g.
7
+ [Rodauth] or [rom-sql]), or you're transitioning from Active Record to Sequel,
8
+ or if you just want to use Sequel for more complex queries, and you want to
9
+ avoid creating new database connections.
10
10
 
11
11
  It works on ActiveRecord 4.2+ and fully supports PostgresSQL, MySQL and SQLite
12
- adapters, both the native ones and JDBC (JRuby). There is attempted suppport
13
- for [Oracle enhanced] and [SQL Server] Active Record adapters (`oracle` and
14
- `tinytds` in Sequel). Other adapters might work too, but their integration
15
- hasn't been tested.
12
+ adapters, both native and JDBC (JRuby). There is attempted suppport for [Oracle
13
+ enhanced] and [SQL Server] Active Record adapters (`oracle` and `tinytds` in
14
+ Sequel). Other adapters might work too, but their integration hasn't been
15
+ tested.
16
+
17
+ ## Why reuse the database connection?
18
+
19
+ At first it might appear that, as long as you're fine with the performance
20
+ impact of your database server having to maintain additional open connections,
21
+ it would be fine if Sequel had its own database connection. However, there are
22
+ additional caveats when you try to combine it with Active Record.
23
+
24
+ If Sequel and Active Record each have their own connections, then it's not
25
+ possible to combine their transactions. If we executed a Sequel query inside of
26
+ an Active Record transaction, that query won't actually be executed inside a
27
+ database transaction. This is because transactions are tied to the database
28
+ connection; if one connection opens a transaction, this doesn't affect queries
29
+ executed on a different connection, even if both connections are used in the
30
+ same ruby process. With this library, transactions and queries can be
31
+ seamlessly combined between Active Record and Sequel.
32
+
33
+ In Rails context, there are additional considerations for a Sequel connection
34
+ to play nicely. Connecting and disconnecting would have to go in lockstep with
35
+ Active Record, to make commands such as `rails db:create` and `rails db:drop`
36
+ work. You'd also need to find a way for system tests and the app running in the
37
+ background to share the same database connection, which is something Sequel
38
+ wasn't designed for. Reusing Active Record's connection means (dis)connecting
39
+ and sharing between threads is all handled automatically.
16
40
 
17
41
  ## Installation
18
42
 
@@ -140,9 +164,8 @@ DB.transaction(auto_savepoint: true) do
140
164
  end
141
165
  #>> BEGIN
142
166
  #>> SAVEPOINT active_record_1
143
- #>> RELEASE SAVEPOINT active_record_1
167
+ #>> ROLLBACK TO SAVEPOINT active_record_1
144
168
  #>> COMMIT
145
- #>> after commit
146
169
  ```
147
170
 
148
171
  In case of (a) adding a transaction hook while Active Record holds the
@@ -168,13 +191,13 @@ end
168
191
  # after a savepoint is released, if the enclosing transaction is not joinable.
169
192
  ActiveRecord::Base.transaction(joinable: false) do
170
193
  DB.transaction do
171
- DB.after_commit { puts "after commit" }
194
+ DB.after_commit { puts "after savepoint release" }
172
195
  end
173
196
  end
174
197
  #>> BEGIN
175
198
  #>> SAVEPOINT active_record_1
176
199
  #>> RELEASE SAVEPOINT active_record_1
177
- #>> after commit
200
+ #>> after savepoint release
178
201
  #>> COMMIT
179
202
  ```
180
203
 
@@ -10,6 +10,11 @@ module Sequel
10
10
 
11
11
  Utils.add_prepared_statements_cache(conn)
12
12
 
13
+ # compatibility for pg_streaming database extension from sequel_pg gem
14
+ if defined?(Sequel::Postgres::Streaming) && is_a?(Sequel::Postgres::Streaming)
15
+ conn.extend(Sequel::Postgres::Streaming::AdapterMethods)
16
+ end
17
+
13
18
  yield conn
14
19
  end
15
20
  end
@@ -70,11 +75,11 @@ module Sequel
70
75
  # yield the results, otherwise, return the number of changed rows.
71
76
  def execute(sql, args = nil)
72
77
  args = args.map { |v| @db.bound_variable_arg(v, self) } if args
73
- result = check_disconnect_errors { execute_query(sql, args) }
78
+ q = check_disconnect_errors { execute_query(sql, args) }
74
79
 
75
- block_given? ? yield(result) : result.cmd_tuples
80
+ block_given? ? yield(q) : q.cmd_tuples
76
81
  ensure
77
- result.clear if result
82
+ q.clear if q && q.respond_to?(:clear)
78
83
  end
79
84
 
80
85
  private
@@ -133,14 +133,18 @@ module Sequel
133
133
  # Active Record doesn't guarantee that a single connection can only be used
134
134
  # by one thread at a time, so we need to use locking, which is what Active
135
135
  # Record does internally as well.
136
- def activerecord_lock
137
- return yield if ActiveRecord.version < Gem::Version.new("5.1.0")
138
-
139
- activerecord_connection.lock.synchronize do
140
- ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
141
- yield
136
+ if ActiveRecord.version >= Gem::Version.new("5.1.0")
137
+ def activerecord_lock
138
+ activerecord_connection.lock.synchronize do
139
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
140
+ yield
141
+ end
142
142
  end
143
143
  end
144
+ else
145
+ def activerecord_lock
146
+ yield
147
+ end
144
148
  end
145
149
 
146
150
  def activerecord_connection
@@ -157,7 +161,7 @@ module Sequel
157
161
  )
158
162
  end
159
163
 
160
- if ActiveRecord::VERSION::MAJOR >= 7
164
+ if ActiveRecord.version >= Gem::Version.new("7.0")
161
165
  def activerecord_timezone
162
166
  ActiveRecord.default_timezone
163
167
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.2.5"
3
+ spec.version = "1.2.8"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
@@ -11,11 +11,11 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.required_ruby_version = ">= 2.4"
13
13
 
14
- spec.add_dependency "sequel", "~> 5.16"
14
+ spec.add_dependency "sequel", "~> 5.38"
15
+ spec.add_dependency "sequel_pg" unless RUBY_ENGINE == "jruby"
15
16
  spec.add_dependency "activerecord", ">= 4.2", "< 8"
16
17
  spec.add_dependency "after_commit_everywhere", "~> 1.1"
17
18
 
18
- spec.add_development_dependency "sequel", "~> 5.38"
19
19
  spec.add_development_dependency "minitest"
20
20
  spec.add_development_dependency "warning"
21
21
 
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.2.5
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-18 00:00:00.000000000 Z
11
+ date: 2022-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.16'
19
+ version: '5.38'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.16'
26
+ version: '5.38'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sequel_pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: activerecord
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +72,6 @@ dependencies:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
74
  version: '1.1'
61
- - !ruby/object:Gem::Dependency
62
- name: sequel
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '5.38'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '5.38'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: minitest
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.2.15
141
+ rubygems_version: 3.3.3
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Allows Sequel to use ActiveRecord connection for database interaction.