active_record_proxy_adapters 0.4.6 → 0.5.0
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/lib/active_record/connection_adapters/sqlite3_proxy_adapter.rb +42 -0
- data/lib/active_record/tasks/sqlite3_proxy_database_tasks.rb +19 -0
- data/lib/active_record_proxy_adapters/connection_handling/sqlite3.rb +68 -0
- data/lib/active_record_proxy_adapters/connection_handling.rb +1 -0
- data/lib/active_record_proxy_adapters/railtie.rb +3 -0
- data/lib/active_record_proxy_adapters/sqlite3_proxy.rb +10 -0
- data/lib/active_record_proxy_adapters/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b25888bc158e220dfb06b349f47c467ef04dee2889a3e7ad6624ead7f2a6ed29
|
4
|
+
data.tar.gz: e0caf99eb8ae9e535a5c68a2c4a1a74471d67d023abc6afb6b1ebd5e2ade1f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbff3cd696e3e52da998dbd44d1505f207f5bd81a1fc014eb6d95d46237ed49d4793c4084ecf34c761754ffabf5372202036ec33e427b80543f085d9c03a90c9
|
7
|
+
data.tar.gz: ae8121a5a61036bce0433d040e3b27bf130fae80084f08379108943afa369101cf3cb17e7b3ea14c3770f03b9e03e30098d250a6535646cda41c5ac89e16da61
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record/tasks/sqlite3_proxy_database_tasks"
|
4
|
+
require "active_record/connection_adapters/sqlite3_adapter"
|
5
|
+
require "active_record_proxy_adapters/active_record_context"
|
6
|
+
require "active_record_proxy_adapters/hijackable"
|
7
|
+
require "active_record_proxy_adapters/sqlite3_proxy"
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
module ConnectionAdapters
|
11
|
+
# This adapter is a proxy to the original SQLite3Adapter, allowing the use of the
|
12
|
+
# ActiveRecordProxyAdapters::PrimaryReplicaProxy.
|
13
|
+
class SQLite3ProxyAdapter < SQLite3Adapter
|
14
|
+
include ActiveRecordProxyAdapters::Hijackable
|
15
|
+
|
16
|
+
ADAPTER_NAME = "SQLite3Proxy"
|
17
|
+
|
18
|
+
delegate_to_proxy(*ActiveRecordProxyAdapters::ActiveRecordContext.hijackable_methods)
|
19
|
+
|
20
|
+
def initialize(...)
|
21
|
+
@proxy = ActiveRecordProxyAdapters::SQLite3Proxy.new(self)
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :proxy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if ActiveRecordProxyAdapters::ActiveRecordContext.active_record_v7_2_or_greater?
|
34
|
+
ActiveRecord::ConnectionAdapters.register(
|
35
|
+
"sqlite3_proxy",
|
36
|
+
"ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter",
|
37
|
+
"active_record/connection_adapters/sqlite3_proxy_adapter"
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
ActiveSupport.run_load_hooks(:active_record_sqlite3proxyadapter,
|
42
|
+
ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record_proxy_adapters/database_tasks"
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Tasks
|
7
|
+
# Defines the sqlite3 tasks for dropping, creating, loading schema and dumping schema.
|
8
|
+
# Bypasses all the proxy logic to send all requests to primary.
|
9
|
+
class SQLite3ProxyDatabaseTasks < SQLiteDatabaseTasks
|
10
|
+
include ActiveRecordProxyAdapters::DatabaseTasks
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Allow proxy adapter to run rake tasks, i.e. db:drop, db:create, db:schema:load db:migrate, etc...
|
16
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(
|
17
|
+
/sqlite3_proxy/,
|
18
|
+
"ActiveRecord::Tasks::SQLite3ProxyDatabaseTasks"
|
19
|
+
)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "active_record/connection_adapters/sqlite3_proxy_adapter"
|
5
|
+
rescue LoadError
|
6
|
+
# sqlite3 not available
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
module ActiveRecordProxyAdapters
|
11
|
+
module SQLite3
|
12
|
+
# Module to extend ActiveRecord::Base with the connection handling methods.
|
13
|
+
# Required to make adapter work in ActiveRecord versions <= 7.2.x
|
14
|
+
module ConnectionHandling
|
15
|
+
def sqlite3_proxy_adapter_class
|
16
|
+
ActiveRecord::ConnectionAdapters::SQLite3ProxyAdapter
|
17
|
+
end
|
18
|
+
|
19
|
+
def sqlite3_proxy_connection(config)
|
20
|
+
connection_factory_mapping
|
21
|
+
.fetch("#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}")
|
22
|
+
.call(config)
|
23
|
+
end
|
24
|
+
|
25
|
+
def connection_factory_mapping
|
26
|
+
{
|
27
|
+
"7.0" => ->(config) { sqlite3_proxy_connection_ar_v70(config) },
|
28
|
+
"7.1" => ->(config) { sqlite3_proxy_connection_ar_v71(config) }
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def sqlite3_proxy_connection_ar_v70(config) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
|
33
|
+
config = config.symbolize_keys
|
34
|
+
|
35
|
+
# Require database.
|
36
|
+
raise ArgumentError, "No database file specified. Missing argument: database" unless config[:database]
|
37
|
+
|
38
|
+
# Allow database path relative to Rails.root, but only if the database
|
39
|
+
# path is not the special path that tells sqlite to build a database only
|
40
|
+
# in memory.
|
41
|
+
if ":memory:" != config[:database] && !config[:database].to_s.start_with?("file:") # rubocop:disable Style/YodaCondition
|
42
|
+
config[:database] = File.expand_path(config[:database], Rails.root) if defined?(Rails.root)
|
43
|
+
dirname = File.dirname(config[:database])
|
44
|
+
Dir.mkdir(dirname) unless File.directory?(dirname)
|
45
|
+
end
|
46
|
+
|
47
|
+
db = ::SQLite3::Database.new(
|
48
|
+
config[:database].to_s,
|
49
|
+
config.merge(results_as_hash: true)
|
50
|
+
)
|
51
|
+
|
52
|
+
sqlite3_proxy_adapter_class.new(db, logger, nil, config)
|
53
|
+
rescue Errno::ENOENT => e
|
54
|
+
raise ActiveRecord::NoDatabaseError if e.message.include?("No such file or directory")
|
55
|
+
|
56
|
+
raise
|
57
|
+
end
|
58
|
+
|
59
|
+
def sqlite3_proxy_connection_ar_v71(config)
|
60
|
+
sqlite3_proxy_adapter_class.new(config)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
ActiveSupport.on_load(:active_record) do
|
67
|
+
ActiveRecord::Base.extend(ActiveRecordProxyAdapters::SQLite3::ConnectionHandling)
|
68
|
+
end
|
@@ -3,3 +3,4 @@
|
|
3
3
|
require "active_record_proxy_adapters/connection_handling/postgresql"
|
4
4
|
require "active_record_proxy_adapters/connection_handling/mysql2"
|
5
5
|
require "active_record_proxy_adapters/connection_handling/trilogy"
|
6
|
+
require "active_record_proxy_adapters/connection_handling/sqlite3"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record_proxy_adapters/primary_replica_proxy"
|
4
|
+
require "active_record_proxy_adapters/active_record_context"
|
5
|
+
|
6
|
+
module ActiveRecordProxyAdapters
|
7
|
+
# Proxy to the original SQLite3Adapter, allowing the use of the ActiveRecordProxyAdapters::PrimaryReplicaProxy.
|
8
|
+
class SQLite3Proxy < PrimaryReplicaProxy
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_proxy_adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cruz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-22 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -65,9 +65,11 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- lib/active_record/connection_adapters/mysql2_proxy_adapter.rb
|
67
67
|
- lib/active_record/connection_adapters/postgresql_proxy_adapter.rb
|
68
|
+
- lib/active_record/connection_adapters/sqlite3_proxy_adapter.rb
|
68
69
|
- lib/active_record/connection_adapters/trilogy_proxy_adapter.rb
|
69
70
|
- lib/active_record/tasks/mysql2_proxy_database_tasks.rb
|
70
71
|
- lib/active_record/tasks/postgresql_proxy_database_tasks.rb
|
72
|
+
- lib/active_record/tasks/sqlite3_proxy_database_tasks.rb
|
71
73
|
- lib/active_record/tasks/trilogy_proxy_database_tasks.rb
|
72
74
|
- lib/active_record_proxy_adapters.rb
|
73
75
|
- lib/active_record_proxy_adapters/active_record_context.rb
|
@@ -75,6 +77,7 @@ files:
|
|
75
77
|
- lib/active_record_proxy_adapters/connection_handling.rb
|
76
78
|
- lib/active_record_proxy_adapters/connection_handling/mysql2.rb
|
77
79
|
- lib/active_record_proxy_adapters/connection_handling/postgresql.rb
|
80
|
+
- lib/active_record_proxy_adapters/connection_handling/sqlite3.rb
|
78
81
|
- lib/active_record_proxy_adapters/connection_handling/trilogy.rb
|
79
82
|
- lib/active_record_proxy_adapters/database_tasks.rb
|
80
83
|
- lib/active_record_proxy_adapters/hijackable.rb
|
@@ -83,6 +86,7 @@ files:
|
|
83
86
|
- lib/active_record_proxy_adapters/postgresql_proxy.rb
|
84
87
|
- lib/active_record_proxy_adapters/primary_replica_proxy.rb
|
85
88
|
- lib/active_record_proxy_adapters/railtie.rb
|
89
|
+
- lib/active_record_proxy_adapters/sqlite3_proxy.rb
|
86
90
|
- lib/active_record_proxy_adapters/trilogy_proxy.rb
|
87
91
|
- lib/active_record_proxy_adapters/version.rb
|
88
92
|
homepage: https://github.com/Nasdaq/active_record_proxy_adapters
|