Sha256: a303273d72ae46397b92f50612301b5b1108688761cbe2d0808188746423cc1e

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

require_relative 'abstract'

module Hanami
  module Model
    module Sql
      module Consoles
        # PostgreSQL adapter
        #
        # @since 0.7.0
        # @api private
        class Postgresql < Abstract
          # @since 0.7.0
          # @api private
          COMMAND = 'psql'.freeze

          # @since 0.7.0
          # @api private
          PASSWORD = 'PGPASSWORD'.freeze

          # @since 0.7.0
          # @api private
          def connection_string
            configure_password
            concat(command, host, database, port, username)
          end

          private

          # @since 0.7.0
          # @api private
          def command
            COMMAND
          end

          # @since 0.7.0
          # @api private
          def host
            " -h #{@uri.host}"
          end

          # @since 0.7.0
          # @api private
          def database
            " -d #{database_name}"
          end

          # @since 0.7.0
          # @api private
          def port
            " -p #{@uri.port}" unless @uri.port.nil?
          end

          # @since 0.7.0
          # @api private
          def username
            " -U #{@uri.user}" unless @uri.user.nil?
          end

          # @since 0.7.0
          # @api private
          def configure_password
            ENV[PASSWORD] = @uri.password unless @uri.password.nil?
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hanami-model-1.0.1 lib/hanami/model/sql/consoles/postgresql.rb
hanami-model-1.0.0 lib/hanami/model/sql/consoles/postgresql.rb
hanami-model-1.0.0.rc1 lib/hanami/model/sql/consoles/postgresql.rb
hanami-model-1.0.0.beta3 lib/hanami/model/sql/consoles/postgresql.rb
hanami-model-1.0.0.beta2 lib/hanami/model/sql/consoles/postgresql.rb
hanami-model-1.0.0.beta1 lib/hanami/model/sql/consoles/postgresql.rb
hanami-model-0.7.0 lib/hanami/model/sql/consoles/postgresql.rb