pub struct Transaction { /* private fields */ }Expand description
A PostgreSQL transaction for the synchronous connection.
This struct provides transaction control. The connection is passed
to commit and rollback methods to execute the transaction commands.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn commit(self, conn: &mut Conn) -> Result<()>
pub fn commit(self, conn: &mut Conn) -> Result<()>
Commit the transaction.
This consumes the transaction and sends a COMMIT statement to the server. The connection must be passed as an argument to execute the commit.
§Errors
Returns Error::InvalidUsage if the connection is not the same
as the one that started the transaction.
Sourcepub fn rollback(self, conn: &mut Conn) -> Result<()>
pub fn rollback(self, conn: &mut Conn) -> Result<()>
Rollback the transaction.
This consumes the transaction and sends a ROLLBACK statement to the server. The connection must be passed as an argument to execute the rollback.
§Errors
Returns Error::InvalidUsage if the connection is not the same
as the one that started the transaction.
Sourcepub fn exec_portal<S: IntoStatement, P: ToParams>(
&self,
conn: &mut Conn,
statement: S,
params: P,
) -> Result<NamedPortal<'_>>
pub fn exec_portal<S: IntoStatement, P: ToParams>( &self, conn: &mut Conn, statement: S, params: P, ) -> Result<NamedPortal<'_>>
Create a named portal for iterative row fetching within this transaction.
Named portals are safe to use within an explicit transaction because SYNC messages do not destroy them (only COMMIT/ROLLBACK does).
The statement can be either:
- A
&PreparedStatementreturned fromconn.prepare() - A raw SQL
&strfor one-shot execution
§Example
let tx = conn.begin()?;
let mut portal = tx.exec_portal(&mut conn, &stmt, ())?;
while !portal.is_complete() {
let rows: Vec<(i32,)> = portal.execute_collect(&mut conn, 100)?;
process(rows);
}
portal.close(&mut conn)?;
tx.commit(&mut conn)?;§Errors
Returns Error::InvalidUsage if the connection is not the same
as the one that started the transaction.