A fully-asynchronous Postgres client. Postgres has a notion of "statements", which are named or unnamed SQL commands, and of "portals", where a portal is an instance of a result. All queries to the database follow the same sequence: parse, bind, execute, close (portal and/or statement).
Both statements and portals can be named or unnamed, although
prototype code might be easier to write using only the query
method of the Connection type, which does the correct sequence
using the unnamed statement and unnamed portal.
Contrarily to synchronous clients, this client needs to store
requests in the event loop while doing asynchronous I/O. The
precise type for this storage needs to be provided by the user of
this crate, and needs to implement both the Request and
HandleRow traits.
This crate provides two API levels:
-
A higher-level one based using
spawn_connection, which uses an existing event loop. This API requires an existing instance ofRequest+HandleRow. -
A lower-level one based on the
Connectiontype, which might be used to build more complex, or more direct pipelines, such as tunneling through another protocol, or waiting for a query to be executed by the server.
extern crate tokio_core;
extern crate pleingres;
extern crate futures;
extern crate env_logger;
use Arc;
use ToSocketAddrs;
use Future;
// A `Request` is the type used for communication with the
// client event loop. It is used both for sending input and
// receiving output.
// Requests must implement the `pleingres::Request` trait,
// meaning they can be converted to commands to be sent to
// the server.