Trait sqlx_postgres::PgPoolCopyExt

source ·
pub trait PgPoolCopyExt {
    // Required methods
    fn copy_in_raw<'a>(
        &'a self,
        statement: &'a str,
    ) -> BoxFuture<'a, Result<PgCopyIn<PoolConnection<Postgres>>>>;
    fn copy_out_raw<'a>(
        &'a self,
        statement: &'a str,
    ) -> BoxFuture<'a, Result<BoxStream<'static, Result<Bytes>>>>;
}
Expand description

Implements methods for directly executing COPY FROM/TO STDOUT on a PgPool.

This is a replacement for the inherent methods on PgPool which could not exist once the Postgres driver was moved out into its own crate.

Required Methods§

source

fn copy_in_raw<'a>( &'a self, statement: &'a str, ) -> BoxFuture<'a, Result<PgCopyIn<PoolConnection<Postgres>>>>

Issue a COPY FROM STDIN statement and begin streaming data to Postgres. This is a more efficient way to import data into Postgres as compared to INSERT but requires one of a few specific data formats (text/CSV/binary).

A single connection will be checked out for the duration.

If statement is anything other than a COPY ... FROM STDIN ... command, an error is returned.

Command examples and accepted formats for COPY data are shown here: https://www.postgresql.org/docs/current/sql-copy.html

§Note

PgCopyIn::finish or PgCopyIn::abort must be called when finished or the connection will return an error the next time it is used.

source

fn copy_out_raw<'a>( &'a self, statement: &'a str, ) -> BoxFuture<'a, Result<BoxStream<'static, Result<Bytes>>>>

Issue a COPY TO STDOUT statement and begin streaming data from Postgres. This is a more efficient way to export data from Postgres but arrives in chunks of one of a few data formats (text/CSV/binary).

If statement is anything other than a COPY ... TO STDOUT ... command, an error is returned.

Note that once this process has begun, unless you read the stream to completion, it can only be canceled in two ways:

  1. by closing the connection, or:
  2. by using another connection to kill the server process that is sending the data as shown in this StackOverflow answer.

If you don’t read the stream to completion, the next time the connection is used it will need to read and discard all the remaining queued data, which could take some time.

Command examples and accepted formats for COPY data are shown here: https://www.postgresql.org/docs/current/sql-copy.html

Implementations on Foreign Types§

source§

impl PgPoolCopyExt for Pool<Postgres>

source§

fn copy_in_raw<'a>( &'a self, statement: &'a str, ) -> BoxFuture<'a, Result<PgCopyIn<PoolConnection<Postgres>>>>

source§

fn copy_out_raw<'a>( &'a self, statement: &'a str, ) -> BoxFuture<'a, Result<BoxStream<'static, Result<Bytes>>>>

Implementors§