Sha256: cdcda4ed981dfb0054fced9af246802191dd0dfaa358292db08b5174bf1e6504

Contents?: true

Size: 937 Bytes

Versions: 2

Compression:

Stored size: 937 Bytes

Contents

require 'uri'

module Hanami
  module Model
    module Sql
      # SQL console
      #
      # @since 0.7.0
      # @api private
      class Console
        extend Forwardable

        def_delegator :console, :connection_string

        # @since 0.7.0
        # @api private
        def initialize(uri)
          @uri = URI.parse(uri)
        end

        private

        # @since 0.7.0
        # @api private
        def console # rubocop:disable Metrics/MethodLength
          case @uri.scheme
          when 'sqlite'
            require 'hanami/model/sql/consoles/sqlite'
            Sql::Consoles::Sqlite.new(@uri)
          when 'postgres'
            require 'hanami/model/sql/consoles/postgresql'
            Sql::Consoles::Postgresql.new(@uri)
          when 'mysql', 'mysql2'
            require 'hanami/model/sql/consoles/mysql'
            Sql::Consoles::Mysql.new(@uri)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-model-1.0.0.beta1 lib/hanami/model/sql/console.rb
hanami-model-0.7.0 lib/hanami/model/sql/console.rb