Sha256: e01d80a5d15f43726c8d1a55468031ae09707d6dff7af4d8a42be15bbe399ff4

Contents?: true

Size: 532 Bytes

Versions: 1

Compression:

Stored size: 532 Bytes

Contents

class Midori::Postgres
  def initialize(*args)
    @db = EM.connect(*args, EM::P::Postgres3)
  end

  def connect(db_name, username, password)
    await(Promise.new(->(resolve, _reject) {
      @db.connect(db_name, username, password).callback do |status|
        resolve.call(status)
      end
    }))
  end

  def query(sql)
    await(Promise.new(->(resolve, _reject) {
      @db.query(sql).callback do |status, result, errors|
        status ? resolve.call(result) : (puts errors; raise RuntimeError)
      end
    }))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-midori-0.1.4 lib/em-midori/extension/postgres.rb