Sha256: 03ea544447d406fa503397ef0bdab703722513cf1d376eae058dce7474e86973

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

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

            def connection_string
              str = 'mysql'
              str << host
              str << database
              str << port if port
              str << username if username
              str << password if password
              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 password
              " -p #{@uri.password}" if @uri.password
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-model-0.6.1 lib/hanami/model/adapters/sql/consoles/mysql.rb
hanami-model-0.6.0 lib/hanami/model/adapters/sql/consoles/mysql.rb