1- use crate :: {
2- AccessMode , ConnectionTrait , DatabaseTransaction , ExecResult , IsolationLevel , QueryResult ,
3- Schema , SchemaBuilder , Statement , StatementBuilder , StreamTrait , TransactionError ,
4- TransactionTrait , error:: * ,
5- } ;
1+ #[ cfg( any( feature = "mock" , feature = "proxy" ) ) ]
2+ use std:: sync:: Arc ;
63use std:: { fmt:: Debug , future:: Future , pin:: Pin } ;
7- use tracing:: instrument;
8- use url:: Url ;
94
105#[ cfg( feature = "sqlx-dep" ) ]
116use sqlx:: pool:: PoolConnection ;
7+ use tracing:: instrument;
8+ use url:: Url ;
129
1310#[ cfg( feature = "rusqlite" ) ]
1411use crate :: driver:: rusqlite:: { RusqliteInnerConnection , RusqliteSharedConnection } ;
15-
16- #[ cfg( any( feature = "mock" , feature = "proxy" ) ) ]
17- use std:: sync:: Arc ;
12+ use crate :: {
13+ ConnectionTrait , DatabaseTransaction , ExecResult , QueryResult , Schema , SchemaBuilder ,
14+ Statement , StatementBuilder , StreamTrait , TransactionConfig , TransactionError ,
15+ TransactionTrait , error:: * ,
16+ } ;
1817
1918/// Handle a database connection depending on the backend enabled by the feature
2019/// flags. This creates a connection pool internally (for SQLx connections),
@@ -351,15 +350,21 @@ impl TransactionTrait for DatabaseConnection {
351350 async fn begin ( & self ) -> Result < DatabaseTransaction , DbErr > {
352351 match & self . inner {
353352 #[ cfg( feature = "sqlx-mysql" ) ]
354- DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => conn. begin ( None , None ) . await ,
353+ DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
354+ conn. begin ( TransactionConfig :: default ( ) ) . await
355+ }
355356 #[ cfg( feature = "sqlx-postgres" ) ]
356357 DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
357- conn. begin ( None , None ) . await
358+ conn. begin ( TransactionConfig :: default ( ) ) . await
358359 }
359360 #[ cfg( feature = "sqlx-sqlite" ) ]
360- DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => conn. begin ( None , None ) . await ,
361+ DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
362+ conn. begin ( TransactionConfig :: default ( ) ) . await
363+ }
361364 #[ cfg( feature = "rusqlite" ) ]
362- DatabaseConnectionType :: RusqliteSharedConnection ( conn) => conn. begin ( None , None ) ,
365+ DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
366+ conn. begin ( TransactionConfig :: default ( ) )
367+ }
363368 #[ cfg( feature = "mock" ) ]
364369 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
365370 DatabaseTransaction :: new_mock ( Arc :: clone ( conn) , None ) . await
@@ -375,26 +380,17 @@ impl TransactionTrait for DatabaseConnection {
375380 #[ instrument( level = "trace" ) ]
376381 async fn begin_with_config (
377382 & self ,
378- _isolation_level : Option < IsolationLevel > ,
379- _access_mode : Option < AccessMode > ,
383+ _config : TransactionConfig ,
380384 ) -> Result < DatabaseTransaction , DbErr > {
381385 match & self . inner {
382386 #[ cfg( feature = "sqlx-mysql" ) ]
383- DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
384- conn. begin ( _isolation_level, _access_mode) . await
385- }
387+ DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => conn. begin ( _config) . await ,
386388 #[ cfg( feature = "sqlx-postgres" ) ]
387- DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
388- conn. begin ( _isolation_level, _access_mode) . await
389- }
389+ DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => conn. begin ( _config) . await ,
390390 #[ cfg( feature = "sqlx-sqlite" ) ]
391- DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
392- conn. begin ( _isolation_level, _access_mode) . await
393- }
391+ DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => conn. begin ( _config) . await ,
394392 #[ cfg( feature = "rusqlite" ) ]
395- DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
396- conn. begin ( _isolation_level, _access_mode)
397- }
393+ DatabaseConnectionType :: RusqliteSharedConnection ( conn) => conn. begin ( _config) ,
398394 #[ cfg( feature = "mock" ) ]
399395 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
400396 DatabaseTransaction :: new_mock ( Arc :: clone ( conn) , None ) . await
@@ -408,7 +404,8 @@ impl TransactionTrait for DatabaseConnection {
408404 }
409405
410406 /// 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.
407+ /// If the function returns an error, the transaction will be rolled back.
408+ /// If it does not return an error, the transaction will be committed.
412409 #[ instrument( level = "trace" , skip( _callback) ) ]
413410 async fn transaction < F , T , E > ( & self , _callback : F ) -> Result < T , TransactionError < E > >
414411 where
@@ -422,19 +419,22 @@ impl TransactionTrait for DatabaseConnection {
422419 match & self . inner {
423420 #[ cfg( feature = "sqlx-mysql" ) ]
424421 DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
425- conn. transaction ( _callback, None , None ) . await
422+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
423+ . await
426424 }
427425 #[ cfg( feature = "sqlx-postgres" ) ]
428426 DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
429- conn. transaction ( _callback, None , None ) . await
427+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
428+ . await
430429 }
431430 #[ cfg( feature = "sqlx-sqlite" ) ]
432431 DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
433- conn. transaction ( _callback, None , None ) . await
432+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
433+ . await
434434 }
435435 #[ cfg( feature = "rusqlite" ) ]
436436 DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
437- conn. transaction ( _callback, None , None )
437+ conn. transaction ( _callback, TransactionConfig :: default ( ) )
438438 }
439439 #[ cfg( feature = "mock" ) ]
440440 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
@@ -455,13 +455,13 @@ impl TransactionTrait for DatabaseConnection {
455455 }
456456
457457 /// 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.
458+ /// If the function returns an error, the transaction will be rolled back.
459+ /// If it does not return an error, the transaction will be committed.
459460 #[ instrument( level = "trace" , skip( _callback) ) ]
460461 async fn transaction_with_config < F , T , E > (
461462 & self ,
462463 _callback : F ,
463- _isolation_level : Option < IsolationLevel > ,
464- _access_mode : Option < AccessMode > ,
464+ _config : TransactionConfig ,
465465 ) -> Result < T , TransactionError < E > >
466466 where
467467 F : for < ' c > FnOnce (
@@ -474,22 +474,19 @@ impl TransactionTrait for DatabaseConnection {
474474 match & self . inner {
475475 #[ cfg( feature = "sqlx-mysql" ) ]
476476 DatabaseConnectionType :: SqlxMySqlPoolConnection ( conn) => {
477- conn. transaction ( _callback, _isolation_level, _access_mode)
478- . await
477+ conn. transaction ( _callback, _config) . await
479478 }
480479 #[ cfg( feature = "sqlx-postgres" ) ]
481480 DatabaseConnectionType :: SqlxPostgresPoolConnection ( conn) => {
482- conn. transaction ( _callback, _isolation_level, _access_mode)
483- . await
481+ conn. transaction ( _callback, _config) . await
484482 }
485483 #[ cfg( feature = "sqlx-sqlite" ) ]
486484 DatabaseConnectionType :: SqlxSqlitePoolConnection ( conn) => {
487- conn. transaction ( _callback, _isolation_level, _access_mode)
488- . await
485+ conn. transaction ( _callback, _config) . await
489486 }
490487 #[ cfg( feature = "rusqlite" ) ]
491488 DatabaseConnectionType :: RusqliteSharedConnection ( conn) => {
492- conn. transaction ( _callback, _isolation_level , _access_mode )
489+ conn. transaction ( _callback, _config )
493490 }
494491 #[ cfg( feature = "mock" ) ]
495492 DatabaseConnectionType :: MockDatabaseConnection ( conn) => {
@@ -556,8 +553,8 @@ impl DatabaseConnection {
556553
557554#[ cfg( feature = "rbac" ) ]
558555impl 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.
556+ /// Load RBAC data from the same database as this connection and setup RBAC
557+ /// engine. If the RBAC engine already exists, it will be replaced.
561558 pub async fn load_rbac ( & self ) -> Result < ( ) , DbErr > {
562559 self . load_rbac_from ( self ) . await
563560 }
@@ -575,7 +572,8 @@ impl DatabaseConnection {
575572 self . rbac . replace ( engine) ;
576573 }
577574
578- /// Create a restricted connection with access control specific for the user.
575+ /// Create a restricted connection with access control specific for the
576+ /// user.
579577 pub fn restricted_for (
580578 & self ,
581579 user_id : crate :: rbac:: RbacUserId ,
0 commit comments