forest_admin_datasource_active_record 1.0.0.pre.beta.82 → 1.0.0.pre.beta.85
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d904af3bd4dc1f7ad3173832d0114e5514f1ca0c883e188cf90a9738a63434
|
4
|
+
data.tar.gz: 783b4531f3319bd262a5c66b7036a370791e87390580c1593e94ac157334ced3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42d12bbca254d8da1645dd6c24e6609b7eed0c480bc25c832654378598386913ce851a6a507cdd9adbc9c991a86479b30235e9943c68c0d1789d6a43fc404c3c
|
7
|
+
data.tar.gz: bd48b0696dd2d4093b89c43450002c9e83546df234d597a492b343332b8ebe1501d8f37ea17e238fe9589017ca42f76eeaaa8f26fd545827c5f3d38d2f42c096
|
@@ -4,15 +4,56 @@ module ForestAdminDatasourceActiveRecord
|
|
4
4
|
class Datasource < ForestAdminDatasourceToolkit::Datasource
|
5
5
|
attr_reader :models
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(
|
8
|
+
db_config = {},
|
9
|
+
support_polymorphic_relations: false,
|
10
|
+
live_query_connections: nil
|
11
|
+
)
|
8
12
|
super()
|
9
13
|
@models = []
|
10
14
|
@support_polymorphic_relations = support_polymorphic_relations
|
11
15
|
@habtm_models = {}
|
16
|
+
@connection_drivers = {}
|
17
|
+
|
18
|
+
@live_query_connections = if live_query_connections.is_a?(String)
|
19
|
+
{ live_query_connections => 'primary' }
|
20
|
+
elsif live_query_connections.is_a?(Hash)
|
21
|
+
live_query_connections
|
22
|
+
else
|
23
|
+
{}
|
24
|
+
end
|
25
|
+
|
12
26
|
init_orm(db_config)
|
13
27
|
generate
|
14
28
|
end
|
15
29
|
|
30
|
+
def execute_native_query(connection_name, query, binds)
|
31
|
+
unless @live_query_connections[connection_name]
|
32
|
+
raise ForestAdminAgent::Http::Exceptions::NotFoundError,
|
33
|
+
"Native query connection '#{connection_name}' is unknown."
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
connection = @live_query_connections[connection_name]
|
38
|
+
|
39
|
+
result = ActiveRecord::Base.connects_to(database: { reading: connection.to_sym }).first.connection
|
40
|
+
.exec_query(query, "SQL Native Query on '#{connection_name}'", binds)
|
41
|
+
|
42
|
+
ForestAdminDatasourceToolkit::Utils::HashHelper.convert_keys(result.to_a)
|
43
|
+
rescue StandardError => e
|
44
|
+
raise ForestAdminDatasourceToolkit::Exceptions::ForestException,
|
45
|
+
"Error when executing SQL query: '#{e.full_message}'"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_binding_symbol(connection_name, binds)
|
50
|
+
if @connection_drivers[@live_query_connections[connection_name]] == 'postgresql'
|
51
|
+
"$#{binds.size + 1}"
|
52
|
+
else
|
53
|
+
'?'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
16
57
|
private
|
17
58
|
|
18
59
|
def generate
|
@@ -43,6 +84,17 @@ module ForestAdminDatasourceActiveRecord
|
|
43
84
|
|
44
85
|
def init_orm(db_config)
|
45
86
|
ActiveRecord::Base.establish_connection(db_config)
|
87
|
+
current_config = ActiveRecord::Base.connection_db_config.env_name
|
88
|
+
configurations = ActiveRecord::Base.configurations
|
89
|
+
.configurations
|
90
|
+
.group_by(&:env_name)
|
91
|
+
.transform_values do |configs|
|
92
|
+
configs.to_h do |config|
|
93
|
+
[config.name, config.adapter]
|
94
|
+
end
|
95
|
+
end.to_h
|
96
|
+
|
97
|
+
@connection_drivers = configurations[current_config]
|
46
98
|
end
|
47
99
|
|
48
100
|
def build_habtm(model)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_datasource_active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.85
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-12-
|
12
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|