Sha256: 24a99669197f1e5f508d1592e79696a92dee0f11b41dc75a91e7382db0cfc360

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

# private
module Simple::SQL::Connection
  def self.active_record_connection
    ActiveRecordConnection
  end

  def self.pg_connection(connection)
    PgConnection.new(connection)
  end

  # A PgConnection object is built around a raw connection. It includes
  # the ConnectionAdapter, which implements ask, all, + friends, and also
  # includes a quiet simplistic Transaction implementation
  class PgConnection
    attr_reader :raw_connection

    def initialize(raw_connection)
      @raw_connection = raw_connection
    end

    include ::Simple::SQL::ConnectionAdapter          # all, ask, first, etc.
    include ::Simple::SQL::SimpleTransactions         # transactions

    extend Forwardable
    delegate [:wait_for_notify] => :raw_connection    # wait_for_notify
  end

  module ActiveRecordConnection
    extend self

    extend ::Simple::SQL::ConnectionAdapter           # all, ask, first, etc.

    extend Forwardable
    delegate [:transaction] => :connection            # transactions
    delegate [:wait_for_notify] => :connection        # wait_for_notify

    def raw_connection
      ActiveRecord::Base.connection.raw_connection
    end

    def connection
      ActiveRecord::Base.connection
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
simple-sql-0.4.8 lib/simple/sql/connection.rb
simple-sql-0.4.7 lib/simple/sql/connection.rb
simple-sql-0.4.5 lib/simple/sql/connection.rb
simple-sql-0.4.4 lib/simple/sql/connection.rb
simple-sql-0.4.3 lib/simple/sql/connection.rb
simple-sql-0.4.2 lib/simple/sql/connection.rb
simple-sql-0.4.1 lib/simple/sql/connection.rb
simple-sql-0.4.0 lib/simple/sql/connection.rb