pub struct PgConnection { /* private fields */ }
Expand description
A connection to a PostgreSQL database.
Implementations§
Source§impl PgConnection
impl PgConnection
pub fn wait_until_ready(&mut self) -> Result<(), Error>
Source§impl PgConnection
impl PgConnection
Sourcepub fn copy_in_raw(&mut self, statement: &str) -> Result<PgCopyIn<&mut Self>>
pub fn copy_in_raw(&mut self, statement: &str) -> Result<PgCopyIn<&mut Self>>
Issue a COPY FROM STDIN
statement and transition the connection to 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).
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.
Sourcepub fn copy_out_raw<'c>(
&'c mut self,
statement: &str,
) -> Result<ChanStream<Bytes>>
pub fn copy_out_raw<'c>( &'c mut self, statement: &str, ) -> Result<ChanStream<Bytes>>
Issue a COPY TO STDOUT
statement and transition the connection to 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:
- by closing the connection, or:
- 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
Trait Implementations§
Source§impl Connection for PgConnection
impl Connection for PgConnection
type Options = PgConnectOptions
Source§fn ping(&mut self) -> Result<(), Error>
fn ping(&mut self) -> Result<(), Error>
Source§fn begin(&mut self) -> Result<Transaction<'_, Self::Database>, Error>where
Self: Sized,
fn begin(&mut self) -> Result<Transaction<'_, Self::Database>, Error>where
Self: Sized,
Source§fn cached_statements_size(&self) -> usize
fn cached_statements_size(&self) -> usize
Source§fn clear_cached_statements(&mut self) -> Result<(), Error>
fn clear_cached_statements(&mut self) -> Result<(), Error>
Source§fn transaction<'a, F, R, E>(&'a mut self, callback: F) -> Result<R, E>
fn transaction<'a, F, R, E>(&'a mut self, callback: F) -> Result<R, E>
Source§impl Debug for PgConnection
impl Debug for PgConnection
Source§impl Executor for &mut PgConnection
impl Executor for &mut PgConnection
type Database = Postgres
Source§fn fetch_many<'q, E>(
&mut self,
query: E,
) -> ChanStream<Either<<Self::Database as Database>::QueryResult, <Self::Database as Database>::Row>>
fn fetch_many<'q, E>( &mut self, query: E, ) -> ChanStream<Either<<Self::Database as Database>::QueryResult, <Self::Database as Database>::Row>>
Source§fn fetch_optional<'q, E>(
&mut self,
query: E,
) -> Result<Option<<Self::Database as Database>::Row>, Error>
fn fetch_optional<'q, E>( &mut self, query: E, ) -> Result<Option<<Self::Database as Database>::Row>, Error>
Source§fn prepare_with<'q>(
&mut self,
sql: &'q str,
parameters: &'q [<Self::Database as Database>::TypeInfo],
) -> Result<<Self::Database as HasStatement>::Statement, Error>
fn prepare_with<'q>( &mut self, sql: &'q str, parameters: &'q [<Self::Database as Database>::TypeInfo], ) -> Result<<Self::Database as HasStatement>::Statement, Error>
Source§fn execute<'q, E>(
&mut self,
query: E,
) -> Result<<Self::Database as Database>::QueryResult, Error>
fn execute<'q, E>( &mut self, query: E, ) -> Result<<Self::Database as Database>::QueryResult, Error>
Source§fn execute_many<'q, E>(
&mut self,
query: E,
) -> ChanStream<<Self::Database as Database>::QueryResult>
fn execute_many<'q, E>( &mut self, query: E, ) -> ChanStream<<Self::Database as Database>::QueryResult>
Source§fn fetch<'q, E>(
&mut self,
query: E,
) -> ChanStream<<Self::Database as Database>::Row>
fn fetch<'q, E>( &mut self, query: E, ) -> ChanStream<<Self::Database as Database>::Row>
Source§fn fetch_all<'q, E>(
&mut self,
query: E,
) -> Result<Vec<<Self::Database as Database>::Row>, Error>
fn fetch_all<'q, E>( &mut self, query: E, ) -> Result<Vec<<Self::Database as Database>::Row>, Error>
Vec
.Source§impl Executor for PgConnection
impl Executor for PgConnection
type Database = Postgres
Source§fn fetch_many<'q, E>(
&mut self,
query: E,
) -> ChanStream<Either<PgQueryResult, PgRow>>
fn fetch_many<'q, E>( &mut self, query: E, ) -> ChanStream<Either<PgQueryResult, PgRow>>
Source§fn fetch_optional<'q, E>(&mut self, query: E) -> Result<Option<PgRow>, Error>
fn fetch_optional<'q, E>(&mut self, query: E) -> Result<Option<PgRow>, Error>
Source§fn prepare_with<'q>(
&mut self,
sql: &'q str,
parameters: &'q [PgTypeInfo],
) -> Result<PgStatement, Error>
fn prepare_with<'q>( &mut self, sql: &'q str, parameters: &'q [PgTypeInfo], ) -> Result<PgStatement, Error>
Source§fn execute<'q, E>(
&mut self,
query: E,
) -> Result<<Self::Database as Database>::QueryResult, Error>
fn execute<'q, E>( &mut self, query: E, ) -> Result<<Self::Database as Database>::QueryResult, Error>
Source§fn execute_many<'q, E>(
&mut self,
query: E,
) -> ChanStream<<Self::Database as Database>::QueryResult>
fn execute_many<'q, E>( &mut self, query: E, ) -> ChanStream<<Self::Database as Database>::QueryResult>
Source§fn fetch<'q, E>(
&mut self,
query: E,
) -> ChanStream<<Self::Database as Database>::Row>
fn fetch<'q, E>( &mut self, query: E, ) -> ChanStream<<Self::Database as Database>::Row>
Source§fn fetch_all<'q, E>(
&mut self,
query: E,
) -> Result<Vec<<Self::Database as Database>::Row>, Error>
fn fetch_all<'q, E>( &mut self, query: E, ) -> Result<Vec<<Self::Database as Database>::Row>, Error>
Vec
.Source§impl<'c> From<&'c mut PgConnection> for MaybePoolConnection<'c, Postgres>
impl<'c> From<&'c mut PgConnection> for MaybePoolConnection<'c, Postgres>
Source§fn from(v: &'c mut PgConnection) -> Self
fn from(v: &'c mut PgConnection) -> Self
Source§impl PgConnectionInfo for PgConnection
impl PgConnectionInfo for PgConnection
Source§fn server_version_num(&self) -> Option<u32>
fn server_version_num(&self) -> Option<u32>
libpq
formatAuto Trait Implementations§
impl !Freeze for PgConnection
impl !RefUnwindSafe for PgConnection
impl Send for PgConnection
impl Sync for PgConnection
impl Unpin for PgConnection
impl !UnwindSafe for PgConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more