Socket
Book a DemoInstallSign in
Socket

em-pg

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

em-pg

0.1.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

EM::PG

One more EventMachine wrapper for Postgresql pg-lib.

Features

  • Fully async including connect and right usage of #busy and #consume_input;
  • All results are standard deferrable objects;
  • Distinct exceptions hierarchy;
  • Wrapper for Green and adapter fot Sequel.

Usage

gem "em-pg"
require "em/pg"

EM.run do
  db = EM::PG.new host: "localhost", port: 5432, dbname: "test", user: "postgres", password: "postgres"
  db.callback do
    q = db.send_query "select 1"
	q.callback do |res|
	  puts "RESULT: #{res.inspect}"
	  EM.stop
	end
	q.errback do |e|
	  raise e
	end
  end
  
  db.errback do |e|
    raise e
  end
end

To all errbacks pass one argument, instance of EM::PG::Error. So it easy to write common handlers and wrappers for something like EM-Synchrony and Green.

Supported methods

  • send_query
  • send_prepare
  • send_query_prepared
  • send_describe_prepared
  • send_describe_portal

All have same semantics as in pg-lib, but result is a Deferrable object

Disconnects

On disconnect all current queries will be failed with exception DisconnectError. You also can pass :on_disconnect callback with options, wich will be called before queries errbacks.

EM::PG doesn't have reconnect strategy, you should handle disconnects by youself.

Logging

You can pass :logger option or set EM::PG.logger for all instances.

Exceptions

 EM::PG::Error
   ConnectionRefusedError
   DisconnectError
   BadStateError
   UnexpectedStateError
     BadConnectionStatusError
	 BadPollStatusError
   PGError
  • ConnectionRefusedError - can't connect. Have field .message with reason;
  • DisconnectError - connection disconnected. Will be raised on all uncompleted queries;
  • BadStateError - you try do something while a wrong state. For example send query on not connected client;
  • UnexpectedStateError - something gone wrong :(
  • PGError - original PG exceptions was raised. Have field .original.

See also

FAQs

Package last updated on 30 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.