Sha256: 2c4a4a5241ba9a444402c649924bffb5f8aa0f38b7e03c357b63ca82029c5451

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

safe_require 'sequel', 'gem install sequel'
require 'sequel/adapters/postgres'

# Management of Postgres Sockets
POSTGRES_SOCKETS = {}

##
# Midori Extension of sequel postgres through meta programming
class Sequel::Postgres::Adapter
  # Call a sql request asynchronously
  # @param [String] sql sql request
  # @param [Array] args args to send
  # @return [Array] sql query result
  def execute_query(sql, args)
    @db.log_connection_yield(sql, self, args) do
      if POSTGRES_SOCKETS[self].nil?
        POSTGRES_SOCKETS[self] = IO::open(socket)
      end
      socket_object = POSTGRES_SOCKETS[self]
      await(Promise.new do |resolve|
        count = 0
        EventLoop.register(socket_object, :rw) do
          begin
            if (count == 0)
              # Writable
              unless is_busy
                send_query(sql)
                count += 1
              end
            else
              # Readable
              EventLoop.deregister(socket_object)
              resolve.call(get_result)
            end
          rescue => e
            resolve.call(PromiseException.new(e))
          end
        end
      end)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
em-midori-0.2.4 lib/midori/extension/sequel/postgres.rb
em-midori-0.2.3 lib/midori/extension/sequel/postgres.rb
em-midori-0.2.2 lib/midori/extension/sequel/postgres.rb
em-midori-0.2.1 lib/midori/extension/sequel/postgres.rb