forest_admin_datasource_active_record 1.0.0.pre.beta.83 → 1.0.0.pre.beta.86
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c6bf7b65420c985052b2b2a96214666a0ee3fbb3437ede7f5ae2ab952f78087
|
4
|
+
data.tar.gz: e57a2b8dbe63b4ebe0c25f0bc62c7f6c2d6a7433662da8899e2dc975ce491914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 988f20ccd3b4b7a4dc0ba60d35f6a5551cda3bd56eefd35e14189dd31ff4bedeb195049dbdfa9a2a03ed298a745ad0c1af9c1dda98edf75f0bf2dde279e549a5
|
7
|
+
data.tar.gz: f26f7ae357400d10b9ab884f82c169a8c1c43b18aed4c2d6ffe200e9b70835f2faaad822c896d7c7c226366f455de5fa59aa0efcdb2123f08164f13a1b67270d
|
@@ -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.86
|
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:
|
12
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|