require 'pg' module EnrichmentDb def self.db_connection @__db_connection ||= PGconn.connect( host:'geo-mappings.cfmmyp7uix0j.ap-southeast-2.rds.amazonaws.com', dbname:'geo', user: 'lexer', password: 'campl3x3r' ) end def self.reset_connection @__api_connection = nil end def self.request(query, values) type = request_type(query) case type when :select, 'select' result = if values EnrichmentDb::db_connection.exec(query, values) else EnrichmentDb::db_connection.exec(query) end when :insert, :drop, :delete, 'insert', 'drop', 'delete' fail EnrichmentDb::RequestError, "Postgres method '#{type}' is unsupported" else fail EnrichmentDb::RequestError, "Postgres query '#{query}' is unsupported" end end def self.request_type(query) result = query.downcase.match(/(^(?:drop|select|insert|delete))/) return unless result result[0] end end