Sha256: 12a6ba9e720be0d715a3d83a61d76f0b40821cd96cd2bb70e2a3eb35a500534b

Contents?: true

Size: 996 Bytes

Versions: 8

Compression:

Stored size: 996 Bytes

Contents

require 'shellwords'
module Lotus
  module Model
    module Adapters
      module Sql
        module Consoles
          class Postgresql
            def initialize(uri)
              @uri = uri
            end

            def connection_string
              configure_password
              str = 'psql'
              str << host
              str << database
              str << port if port
              str << username if username
              str
            end

            private

            def host
              " -h #{@uri.host}"
            end

            def database
              " -d #{@uri.path.sub(/^\//, '')}"
            end

            def port
              " -p #{@uri.port}" if @uri.port
            end

            def username
              " -U #{@uri.user}" if @uri.user
            end

            def configure_password
              ENV['PGPASSWORD'] = @uri.password if @uri.password
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lotus-model-0.5.2 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.5.1 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.5.0 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.4.1 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.4.0 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.3.2 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.3.1 lib/lotus/model/adapters/sql/consoles/postgresql.rb
lotus-model-0.3.0 lib/lotus/model/adapters/sql/consoles/postgresql.rb