MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / transaction

Method transaction

src/database/db_connection.rs:302–340  ·  view source on GitHub ↗
(&self, _callback: F)

Source from the content-addressed store, hash-verified

300 /// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
301 #[instrument(level = "trace", skip(_callback))]
302 async fn transaction<F, T, E>(&self, _callback: F) -> Result<T, TransactionError<E>>
303 where
304 F: for<'c> FnOnce(
305 &'c DatabaseTransaction,
306 ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>>
307 + Send,
308 T: Send,
309 E: std::fmt::Display + std::fmt::Debug + Send,
310 {
311 match self {
312 #[cfg(feature = "sqlx-mysql")]
313 DatabaseConnection::SqlxMySqlPoolConnection(conn) => {
314 conn.transaction(_callback, None, None).await
315 }
316 #[cfg(feature = "sqlx-postgres")]
317 DatabaseConnection::SqlxPostgresPoolConnection(conn) => {
318 conn.transaction(_callback, None, None).await
319 }
320 #[cfg(feature = "sqlx-sqlite")]
321 DatabaseConnection::SqlxSqlitePoolConnection(conn) => {
322 conn.transaction(_callback, None, None).await
323 }
324 #[cfg(feature = "mock")]
325 DatabaseConnection::MockDatabaseConnection(conn) => {
326 let transaction = DatabaseTransaction::new_mock(Arc::clone(conn), None)
327 .await
328 .map_err(TransactionError::Connection)?;
329 transaction.run(_callback).await
330 }
331 #[cfg(feature = "proxy")]
332 DatabaseConnection::ProxyDatabaseConnection(conn) => {
333 let transaction = DatabaseTransaction::new_proxy(conn.clone(), None)
334 .await
335 .map_err(TransactionError::Connection)?;
336 transaction.run(_callback).await
337 }
338 DatabaseConnection::Disconnected => Err(conn_err("Disconnected").into()),
339 }
340 }
341
342 /// Execute the function inside a transaction.
343 /// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.

Callers 1

Calls 2

conn_errFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected