pub enum ForgeConn<'a> {
Pool(PoolConnection<Postgres>),
Tx(MutexGuard<'a, Transaction<'static, Postgres>>),
}Expand description
Connection wrapper that implements DerefMut<Target = PgConnection>, making it
compatible with sqlx compile-time checked macros (query_as!, query!).
Obtain via ctx.conn().await? in mutation handlers, or any pool-backed context
(job, cron, daemon, webhook, mcp). QueryContext.db() returns &PgPool which
works directly with macros without needing ForgeConn.
let mut conn = ctx.conn().await?;
sqlx::query_as!(User, "SELECT * FROM users WHERE id = $1", id)
.fetch_one(&mut *conn)
.await?Variants§
Pool(PoolConnection<Postgres>)
Tx(MutexGuard<'a, Transaction<'static, Postgres>>)
Methods from Deref<Target = PgConnection>§
Sourcepub fn server_version_num(&self) -> Option<u32>
pub fn server_version_num(&self) -> Option<u32>
the version number of the server in libpq format
Sourcepub 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.
Sourcepub 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§
Auto Trait Implementations§
impl<'a> Freeze for ForgeConn<'a>
impl<'a> !RefUnwindSafe for ForgeConn<'a>
impl<'a> Send for ForgeConn<'a>
impl<'a> Sync for ForgeConn<'a>
impl<'a> Unpin for ForgeConn<'a>
impl<'a> UnsafeUnpin for ForgeConn<'a>
impl<'a> !UnwindSafe for ForgeConn<'a>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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