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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ceba0e24d5a6a925fde46a68d7d8f1586aa29bf1687e94000d989f6ab522e3e
4
- data.tar.gz: 0d6ef838acd8ce79e5638e83b45c8bbdb72cd919863916ad0d48d5658ab079b8
3
+ metadata.gz: 4181722f3ac149e1843e0372c04cc326341021eef62df0d52efafbf524fb4876
4
+ data.tar.gz: 9e561848f90dc6961e89f8b051b6dac8f896d119bf6f4e25e409fcf5ac1f4562
5
5
  SHA512:
6
- metadata.gz: 7aa9e392a307c55483d432c487ef5a5c0ab6c501e7e3081646f5945ba7fe5322fd29b2eb1d3b81d110f94db0ec252f624fcdcf70a4f903df0cdc434e2851b99b
7
- data.tar.gz: 2ced3df663f4dc6ee3d360625ff12c3a267c9a136c1d9535a54a41d51092691a7e8e316ec39fb8eca207b98807abc623f0a47bcaacbca3dd6c55275997211fba
6
+ metadata.gz: 439be8d21f8eb86b72d0599e0bcfa89e93c032a372bcf4321462cd83435995a9115433bf533a3b88930c2f641b058eb54df7cdca9e80f85979b8dbd632d5919a
7
+ data.tar.gz: 6118678a2c94fbd6d871d15403ab17fc4e52434b422fe7bf1b093aa481ab97d41615cd5037a9a032ce230626a72452c01f0ad7fa23728e9c4f6ee934f03a0898
@@ -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
- MSG_NO_CONNECTION = 'No current database connection. Call Uc3DmpRds.connect first'
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
- puts connection.inspect
46
- puts "CONNECTED? #{ActiveRecord::Base.connected?}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpRds
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-rds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley