lib/timescaledb/connection.rb in timescaledb-0.2.8 vs lib/timescaledb/connection.rb in timescaledb-0.2.9

- old
+ new

@@ -1,8 +1,13 @@ require 'singleton' module Timescaledb + # Minimal connection setup for Timescaledb directly with the PG. + # The concept is use a singleton component that can query + # independently of the ActiveRecord::Base connections. + # This is useful for the extension and hypertable metadata. + # It can also #use_connection from active record if needed. class Connection include Singleton attr_writer :config @@ -32,12 +37,18 @@ # @param [Boolean] True if the connection singleton was configured, otherwise returns false. def connected? !@config.nil? end + # Override the connection with a raw PG connection. + # @param [PG::Connection] connection The raw PG connection. + def use_connection connection + @connection = connection + end + private def connection @connection ||= PG.connect(@config) end end -end \ No newline at end of file +end