class Tetrahedron::Databases::Postgres

Public Class Methods

new(&configurator) click to toggle source
# File lib/tetrahedron/databases/postgres.rb, line 13
def initialize(&configurator)
  @configuration = Configuration.new
  @configuration.instance_eval(&configurator) if block_given?
end

Public Instance Methods

connect() click to toggle source
# File lib/tetrahedron/databases/postgres.rb, line 22
def connect
  # Wait some amount of time before assuming the database is down.
  Service.wait_until_reachable!(:protocol => :tcp,
                                :host => @configuration.host,
                                :port => @configuration.port,
                                :timeout => 15)

  @connection = Sequel.postgres(:host => @configuration.host,
                                :port => @configuration.port,
                                :user => @configuration.user,
                                :password => @configuration.password,
                                :database => @configuration.database,
                                :test => true,
                                :sslmode => :prefer,
                                :max_connections => @configuration.pool)

  true
end
connection() click to toggle source
# File lib/tetrahedron/databases/postgres.rb, line 18
def connection
  @connection
end
disconnect() click to toggle source
# File lib/tetrahedron/databases/postgres.rb, line 41
def disconnect
  @connection.disconnect if @connection
  @connection = nil
  true
end