Sha256: 9609eae429d5083dae0765beed659a663a5f2dc9356f0482b048d1c8d4d0ca31

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

require 'sequel'

module Skalera
  module Services
    class Postgres
      SERVICE_NAME = 'postgres'
      def self.instance(database)
        postgres_config = Diplomat::Service.get(SERVICE_NAME)

        host = postgres_config.Address
        port = postgres_config.ServicePort

        url = "postgres://#{key('user')}:#{key('password')}@#{host}:#{port}/#{database}"
        db = ::Sequel.connect(url)
        at_exit { db.disconnect }
        db
      rescue Diplomat::KeyNotFound
        STDERR.puts "ERROR: service not found: #{SERVICE_NAME}"
      end

      def self.key(key)
        Diplomat.get("postgres/#{key}")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skalera-services-0.2.4 lib/skalera/services/postgres.rb