uc3-dmp-rds 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-rds/adapter.rb +7 -9
- data/lib/uc3-dmp-rds/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4181722f3ac149e1843e0372c04cc326341021eef62df0d52efafbf524fb4876
|
4
|
+
data.tar.gz: 9e561848f90dc6961e89f8b051b6dac8f896d119bf6f4e25e409fcf5ac1f4562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439be8d21f8eb86b72d0599e0bcfa89e93c032a372bcf4321462cd83435995a9115433bf533a3b88930c2f641b058eb54df7cdca9e80f85979b8dbd632d5919a
|
7
|
+
data.tar.gz: 6118678a2c94fbd6d871d15403ab17fc4e52434b422fe7bf1b093aa481ab97d41615cd5037a9a032ce230626a72452c01f0ad7fa23728e9c4f6ee934f03a0898
|
data/lib/uc3-dmp-rds/adapter.rb
CHANGED
@@ -22,7 +22,8 @@ module Uc3DmpRds
|
|
22
22
|
class Adapter
|
23
23
|
MSG_KEYWORDS_INVALID = 'The parameters specified do not match those in the SQL query'
|
24
24
|
MSG_MISSING_CREDENTIALS = 'No username and/or password specified'
|
25
|
-
|
25
|
+
MSG_UNABLE_TO_CONNECT = 'Unable to establish a connection'
|
26
|
+
MSG_UNABLE_TO_QUERY = 'Unable to process the query'
|
26
27
|
|
27
28
|
class << self
|
28
29
|
# Connect to the RDS instance
|
@@ -30,8 +31,6 @@ module Uc3DmpRds
|
|
30
31
|
raise AdapterError, MSG_MISSING_CREDENTIALS if username.nil? || username.to_s.strip.empty? ||
|
31
32
|
password.nil? || password.to_s.strip.empty?
|
32
33
|
|
33
|
-
puts "CONNECT - host: #{ENV['DATABASE_HOST']}, port: #{ENV['DATABASE_PORT']}, name: #{ENV['DATABASE_NAME']}, username: #{username}, password.lenght: #{password.length}"
|
34
|
-
|
35
34
|
connection = ActiveRecord::Base.establish_connection(
|
36
35
|
adapter: 'mysql2',
|
37
36
|
host: ENV.fetch('DATABASE_HOST', nil),
|
@@ -41,21 +40,20 @@ puts "CONNECT - host: #{ENV['DATABASE_HOST']}, port: #{ENV['DATABASE_PORT']}, na
|
|
41
40
|
password: password,
|
42
41
|
encoding: 'utf8mb4'
|
43
42
|
)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
ActiveRecord::Base.connected?
|
43
|
+
!connection.nil?
|
44
|
+
rescue StandardError => e
|
45
|
+
raise AdapterError, "#{MSG_UNABLE_TO_CONNECT} - #{e.message}"
|
49
46
|
end
|
50
47
|
|
51
48
|
# Execute the specified query using ActiveRecord's helpers to sanitize the input
|
52
49
|
def execute_query(sql:, **params)
|
53
|
-
raise AdapterError, MSG_NO_CONNECTION unless ActiveRecord::Base.connected?
|
54
50
|
return [] unless sql.is_a?(String) && !sql.strip.empty? && (params.nil? || params.is_a?(Hash))
|
55
51
|
# Verify that all of the kewords are accounted for and that values were supplied
|
56
52
|
raise AdapterError, MSG_KEYWORDS_INVALID unless _verify_params(sql: sql, params: params)
|
57
53
|
|
58
54
|
ActiveRecord::Base.simple_execute(sql, params)
|
55
|
+
rescue StandardError => e
|
56
|
+
raise AdapterError, "#{MSG_UNABLE_TO_QUERY} - #{e.message}"
|
59
57
|
end
|
60
58
|
|
61
59
|
private
|
data/lib/uc3-dmp-rds/version.rb
CHANGED