pub struct TenantConnection { /* private fields */ }Expand description
A checked-out connection, holding the tenant pool it came from.
The anchor is what makes the residency bound true. A permit lives inside
[TenantPool] and is returned when the last handle drops, so handing back a
bare PoolConnection released the permit while the connection was still
open — sqlx keeps the pool alive behind the connection, so the process could
then admit a ninth resident pool and exceed the budget it claims to enforce.
Dereferences to [PgConnection], so &mut *conn and &mut conn reach an
executor exactly as they did before.
Methods from Deref<Target = PgConnection>§
pub fn server_version_num(&self) -> Option<u32>
pub fn server_version_num(&self) -> Option<u32>
the version number of the server in libpq format
pub async fn copy_in_raw(
&mut self,
statement: &str,
) -> Result<PgCopyIn<&mut PgConnection>, Error>
pub async fn copy_in_raw( &mut self, statement: &str, ) -> Result<PgCopyIn<&mut PgConnection>, Error>
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.
pub async fn copy_out_raw<'c>(
&'c mut self,
statement: &str,
) -> Result<Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + 'c>>, Error>
pub async fn copy_out_raw<'c>( &'c mut self, statement: &str, ) -> Result<Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + 'c>>, Error>
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 Deref for TenantConnection
impl Deref for TenantConnection
Auto Trait Implementations§
impl Freeze for TenantConnection
impl !RefUnwindSafe for TenantConnection
impl Send for TenantConnection
impl Sync for TenantConnection
impl Unpin for TenantConnection
impl UnsafeUnpin for TenantConnection
impl !UnwindSafe for TenantConnection
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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