Sha256: aae23ef5e08bf7612d4e3e1b72a892773c61e1c09af7449f173de14ca755e27d

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module MiniSql
  class Connection

    def self.get(raw_connection, options = {})
      if (defined? ::PG::Connection) && (PG::Connection === raw_connection)
        Postgres::Connection.new(raw_connection, options)
      elsif (defined? ::ArJdbc)
        Postgres::Connection.new(raw_connection, options)
      elsif (defined? ::SQLite3::Database) && (SQLite3::Database === raw_connection)
        Sqlite::Connection.new(raw_connection, options)
      elsif (defined? ::Mysql2::Client) && (Mysql2::Client === raw_connection)
        Mysql::Connection.new(raw_connection, options)
      else
        raise ArgumentError, 'unknown connection type!'
      end
    end

    # Returns a flat array containing all results.
    # Note, if selecting multiple columns array will be flattened
    #
    # @param sql [String] the query to run
    # @param params [Array or Hash], params to apply to query
    # @return [Object] a flat array containing all results
    def query_single(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def query(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def query_hash(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def query_decorator(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def query_each(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def query_each_hash(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def exec(sql, *params)
      raise NotImplementedError, "must be implemented by child connection"
    end

    def build(sql)
      Builder.new(self, sql)
    end

    def escape_string(str)
      raise NotImplementedError, "must be implemented by child connection"
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mini_sql-1.2.0 lib/mini_sql/connection.rb
mini_sql-1.1.3 lib/mini_sql/connection.rb
mini_sql-1.1.2 lib/mini_sql/connection.rb
mini_sql-1.1.1 lib/mini_sql/connection.rb
mini_sql-1.1.0 lib/mini_sql/connection.rb
mini_sql-1.0.1 lib/mini_sql/connection.rb
mini_sql-1.0 lib/mini_sql/connection.rb
mini_sql-0.3 lib/mini_sql/connection.rb