sequel-activerecord_connection 1.2.6 → 1.2.9

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: aa32893e39b55c6e2b8186c216645a4cccfa7e865795e390656ebac83d5ecd1d
4
- data.tar.gz: c8d6ba5b2958de6e8e3d687c75f4a51a60c863a1728de525ef222650cd34b490
3
+ metadata.gz: 9cd2f9d2df2e116227a94f6a005a5f7470178e4ecfc22218fe0a3dc456a2ecd2
4
+ data.tar.gz: 64e96f773827d185768d6190468a350162c3e7e4923a5f5dc565d50ec8064f79
5
5
  SHA512:
6
- metadata.gz: fba2ec585154bfd9477b2ace86b7c6b6b36cc5b4ba11f21a62bde593b1c8069858fb33d4984dced898b02a831f75fd2219c43adb26d67b93d17ce0313965c30a
7
- data.tar.gz: 685f0dd698849465d1902ee7cd4432d2de6ea25f7791707a6defae8f32ff0e66713a4f391573924e79dfe3f91723fa564083b1dbefbf2c2986047205fe024aec
6
+ metadata.gz: 58862596df481839c1668ce4f3062f56255dc5115a2aa8bfb08499c10b76eac0859b51485f639c5fa16459cff170c2531b7c86c0e38efe9d5dfe6bc94a6a2891
7
+ data.tar.gz: 1aa33eb5cd5eb85be84252bd3ddd02ec537e7bf89481882604fc691d72d055d4bd85e6ad97562c44b39c90beabb661ba04ba1a311775b707aa71984f23dc8e25
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
+ ## 1.2.9 (2022-03-15)
2
+
3
+ * Remove `sequel_pg` and `pg` runtime dependencies introduced in the previous version (@janko)
4
+
5
+ ## 1.2.8 (2022-02-28)
6
+
7
+ * Support the pg_streaming database extension from the sequel_pg gem (@janko)
8
+
9
+ ## 1.2.7 (2022-01-20)
10
+
11
+ * Require Sequel 3.38+ (@janko)
12
+
1
13
  ## 1.2.6 (2021-12-26)
2
14
 
3
- * Speed up `#activerecord_lock` by avoiding checking Active Record version at runtime (@janko)
15
+ * Speed up connection access by avoiding checking Active Record version at runtime (@janko)
4
16
 
5
17
  ## 1.2.5 (2021-12-19)
6
18
 
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.2.6"
3
+ spec.version = "1.2.9"
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
15
  spec.add_dependency "activerecord", ">= 4.2", "< 8"
16
16
  spec.add_dependency "after_commit_everywhere", "~> 1.1"
17
17
 
18
- spec.add_development_dependency "sequel", "~> 5.38"
18
+ spec.add_development_dependency "sequel_pg" unless RUBY_ENGINE == "jruby"
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.6
4
+ version: 1.2.9
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-26 00:00:00.000000000 Z
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -16,14 +16,14 @@ 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
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,19 +59,19 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.1'
61
61
  - !ruby/object:Gem::Dependency
62
- name: sequel
62
+ name: sequel_pg
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '5.38'
67
+ version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '5.38'
74
+ version: '0'
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.