[][src]Crate kpgres

An asynchronous, pipelined, PostgreSQL client.

Behavior

Calling a method like Client::query on its own does nothing. The associated request is not sent to the database until the future returned by the method is first polled. Requests are executed in the order that they are first polled, not in the order that their futures are created.

Pipelining

The client supports pipelined requests. Pipelining can improve performance in use cases in which multiple, independent queries need to be executed. In a traditional workflow, each query is sent to the server after the previous query completes. In contrast, pipelining allows the client to send all of the queries to the server up front, minimizing time spent by one side waiting for the other to finish sending data:

            Sequential                              Pipelined
| Client         | Server          |    | Client         | Server          |
|----------------|-----------------|    |----------------|-----------------|
| send query 1   |                 |    | send query 1   |                 |
|                | process query 1 |    | send query 2   | process query 1 |
| receive rows 1 |                 |    | send query 3   | process query 2 |
| send query 2   |                 |    | receive rows 1 | process query 3 |
|                | process query 2 |    | receive rows 2 |                 |
| receive rows 2 |                 |    | receive rows 3 |                 |
| send query 3   |                 |
|                | process query 3 |
| receive rows 3 |                 |

In both cases, the PostgreSQL server is executing the queries sequentially - pipelining just allows both sides of the connection to work concurrently when possible.

Pipelining happens automatically when futures are polled concurrently (for example, by using the futures join combinator):

use futures::future;
use std::future::Future;
use kpgres::{Client, Error, Statement};

async fn pipelined_prepare(
    client: &Client,
) -> Result<(Statement, Statement), Error>
{
    future::try_join(
        client.prepare("SELECT * FROM foo"),
        client.prepare("INSERT INTO bar (id, name) VALUES ($1, $2)")
    ).await
}

SSL/TLS support

TLS support is implemented via external libraries. Client::connect and Config::connect take a TLS implementation as an argument. The NoTls type in this crate can be used when TLS is not required. Otherwise, the postgres-openssl and postgres-native-tls crates provide implementations backed by the openssl and native-tls crates, respectively.

Re-exports

pub use crate::config::Config;
pub use crate::error::Error;
pub use crate::row::Row;
pub use crate::row::SimpleQueryRow;
pub use crate::tls::NoTls;

Modules

binary_copy

Utilities for working with the PostgreSQL binary copy format.

config

Connection configuration.

error

Errors.

row

Rows.

tls

TLS support.

types

Types.

Structs

Client

An asynchronous PostgreSQL client.

Column

Information about a column of a query.

Connection

A connection to a PostgreSQL database.

CopyInSink

A sink for COPY ... FROM STDIN query data.

CopyOutStream

A stream of COPY ... TO STDOUT query data.

Notification

An asynchronous notification.

Portal

A portal.

RowStream

A stream of table rows.

SimpleQueryStream

A stream of simple query results.

Socket

The standard stream type used by the crate.

Statement

A prepared statement.

Transaction

A representation of a PostgreSQL database transaction.

Enums

AsyncMessage

An asynchronous message from the server.

SimpleQueryMessage

Message returned by the SimpleQuery stream.

Traits

ToStatement

A trait abstracting over prepared and unprepared statements.

Functions

connect

A convenience function which parses a connection string and connects to the database.