11use crate :: {
2- AccessMode , ConnectionTrait , DatabaseTransaction , ExecResult , IsolationLevel , QueryResult ,
3- Schema , SchemaBuilder , Statement , StatementBuilder , StreamTrait , TransactionError ,
2+ ConnectionTrait , DatabaseTransaction , ExecResult , QueryResult , Schema , SchemaBuilder ,
3+ Statement , StatementBuilder , StreamTrait , TransactionConfig , TransactionError ,
44 TransactionTrait , error:: * ,
55} ;
66use std:: { fmt:: Debug , future:: Future , pin:: Pin } ;
@@ -351,15 +351,21 @@ impl TransactionTrait for DatabaseConnection {
351351 async fn begin ( & self ) -> Result < DatabaseTransaction , DbErr > {
352352 match & self . inner {
353353 #[ cfg( feature = "sqlx-mysql" ) ]
354- DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => conn. begin ( None , None ) . await ,
354+ DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
355+ conn. begin ( TransactionConfig :: default ( ) ) . await
356+ }
355357 #[ cfg( feature = "sqlx-postgres" ) ]
356358 DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
357- conn. begin ( None , None ) . await
359+ conn. begin ( TransactionConfig :: default ( ) ) . await
358360 }
359361 #[ cfg( feature = "sqlx-sqlite" ) ]
360- DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => conn. begin ( None , None ) . await ,
362+ DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
363+ conn. begin ( TransactionConfig :: default ( ) ) . await
364+ }
361365 #[ cfg( feature = "rusqlite" ) ]
362- DatabaseConnectionType :: RusqliteSharedConnection ( conn) => conn. begin ( None , None ) ,
366+ DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
367+ conn. begin ( TransactionConfig :: default ( ) )
368+ }
363369 #[ cfg( feature = "mock" ) ]
364370 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
365371 DatabaseTransaction :: new_mock ( Arc :: clone ( conn) , None ) . await
@@ -375,26 +381,17 @@ impl TransactionTrait for DatabaseConnection {
375381 #[ instrument( level = "trace" ) ]
376382 async fn begin_with_config (
377383 & self ,
378- _isolation_level : Option < IsolationLevel > ,
379- _access_mode : Option < AccessMode > ,
384+ _config : TransactionConfig ,
380385 ) -> Result < DatabaseTransaction , DbErr > {
381386 match & self . inner {
382387 #[ cfg( feature = "sqlx-mysql" ) ]
383- DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
384- conn. begin ( _isolation_level, _access_mode) . await
385- }
388+ DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => conn. begin ( _config) . await ,
386389 #[ cfg( feature = "sqlx-postgres" ) ]
387- DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
388- conn. begin ( _isolation_level, _access_mode) . await
389- }
390+ DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => conn. begin ( _config) . await ,
390391 #[ cfg( feature = "sqlx-sqlite" ) ]
391- DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
392- conn. begin ( _isolation_level, _access_mode) . await
393- }
392+ DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => conn. begin ( _config) . await ,
394393 #[ cfg( feature = "rusqlite" ) ]
395- DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
396- conn. begin ( _isolation_level, _access_mode)
397- }
394+ DatabaseConnectionType :: RusqliteSharedConnection ( conn) => conn. begin ( _config) ,
398395 #[ cfg( feature = "mock" ) ]
399396 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
400397 DatabaseTransaction :: new_mock ( Arc :: clone ( conn) , None ) . await
@@ -408,7 +405,8 @@ impl TransactionTrait for DatabaseConnection {
408405 }
409406
410407 /// Execute the function inside a transaction.
411- /// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
408+ /// If the function returns an error, the transaction will be rolled back.
409+ /// If it does not return an error, the transaction will be committed.
412410 #[ instrument( level = "trace" , skip( _callback) ) ]
413411 async fn transaction < F , T , E > ( & self , _callback : F ) -> Result < T , TransactionError < E > >
414412 where
@@ -422,19 +420,22 @@ impl TransactionTrait for DatabaseConnection {
422420 match & self . inner {
423421 #[ cfg( feature = "sqlx-mysql" ) ]
424422 DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
425- conn. transaction ( _callback, None , None ) . await
423+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
424+ . await
426425 }
427426 #[ cfg( feature = "sqlx-postgres" ) ]
428427 DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
429- conn. transaction ( _callback, None , None ) . await
428+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
429+ . await
430430 }
431431 #[ cfg( feature = "sqlx-sqlite" ) ]
432432 DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
433- conn. transaction ( _callback, None , None ) . await
433+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
434+ . await
434435 }
435436 #[ cfg( feature = "rusqlite" ) ]
436437 DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
437- conn. transaction ( _callback, None , None )
438+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
438439 }
439440 #[ cfg( feature = "mock" ) ]
440441 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
@@ -455,13 +456,13 @@ impl TransactionTrait for DatabaseConnection {
455456 }
456457
457458 /// Execute the function inside a transaction.
458- /// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.
459+ /// If the function returns an error, the transaction will be rolled back.
460+ /// If it does not return an error, the transaction will be committed.
459461 #[ instrument( level = "trace" , skip( _callback) ) ]
460462 async fn transaction_with_config < F , T , E > (
461463 & self ,
462464 _callback : F ,
463- _isolation_level : Option < IsolationLevel > ,
464- _access_mode : Option < AccessMode > ,
465+ _config : TransactionConfig ,
465466 ) -> Result < T , TransactionError < E > >
466467 where
467468 F : for < ' c > FnOnce (
@@ -474,22 +475,19 @@ impl TransactionTrait for DatabaseConnection {
474475 match & self . inner {
475476 #[ cfg( feature = "sqlx-mysql" ) ]
476477 DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
477- conn. transaction ( _callback, _isolation_level, _access_mode)
478- . await
478+ conn. transaction ( _callback, _config) . await
479479 }
480480 #[ cfg( feature = "sqlx-postgres" ) ]
481481 DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
482- conn. transaction ( _callback, _isolation_level, _access_mode)
483- . await
482+ conn. transaction ( _callback, _config) . await
484483 }
485484 #[ cfg( feature = "sqlx-sqlite" ) ]
486485 DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
487- conn. transaction ( _callback, _isolation_level, _access_mode)
488- . await
486+ conn. transaction ( _callback, _config) . await
489487 }
490488 #[ cfg( feature = "rusqlite" ) ]
491489 DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
492- conn. transaction ( _callback, _isolation_level , _access_mode )
490+ conn. transaction ( _callback, _config )
493491 }
494492 #[ cfg( feature = "mock" ) ]
495493 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
@@ -556,8 +554,8 @@ impl DatabaseConnection {
556554
557555#[ cfg( feature = "rbac" ) ]
558556impl DatabaseConnection {
559- /// Load RBAC data from the same database as this connection and setup RBAC engine.
560- /// If the RBAC engine already exists, it will be replaced.
557+ /// Load RBAC data from the same database as this connection and setup RBAC
558+ /// engine. If the RBAC engine already exists, it will be replaced.
561559 pub async fn load_rbac ( & self ) -> Result < ( ) , DbErr > {
562560 self . load_rbac_from ( self ) . await
563561 }
@@ -575,7 +573,8 @@ impl DatabaseConnection {
575573 self . rbac . replace ( engine) ;
576574 }
577575
578- /// Create a restricted connection with access control specific for the user.
576+ /// Create a restricted connection with access control specific for the
577+ /// user.
579578 pub fn restricted_for (
580579 & self ,
581580 user_id : crate :: rbac:: RbacUserId ,
0 commit comments