Method: Rake::DataTask::Postgres#initialize
- Defined in:
- lib/data_task/adapters/postgres.rb
#initialize(options) ⇒ Sqlite
Connect to a PostgreSQL database.
If we’ve already used this class to connect to the same host, port, and database with the same username, re-use that connection for this instance.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/data_task/adapters/postgres.rb', line 34 def initialize host = ['host'] || 'localhost' port = ['port'] || 5432 database = ['database'] username = ['username'] # always reuse an existing connection if it matches on these connection options = {:host => host, :port => port, :database => database, :username => username} existing_connection = self.class.persisted_connection() if existing_connection.nil? # create and persist a new connection @connection = PG::Connection.new( host, port, nil, nil, database, username, ['password'] || '' ) @connection.set_notice_processor do |msg| if msg =~ /^ERROR:/ LOG.error('psql') { msg.gsub(/\n/,'; ') } else LOG.info('psql') { msg.gsub(/\n/,'; ') } end end self.class.persist_connection(@connection, ) else # reuse an existing connection @connection = existing_connection end # set up trackig if it isn't set up already set_up_tracking if !tracking_tables? end |