@@ -23,7 +23,7 @@ use tokio_postgres::{types::ToSql, Row};
23
23
/// It is not exposed to python.
24
24
#[ allow( clippy:: module_name_repetitions) ]
25
25
pub struct RustTransaction {
26
- pub db_client : Arc < tokio :: sync :: RwLock < Object > > ,
26
+ pub db_client : Arc < Object > ,
27
27
is_started : Arc < tokio:: sync:: RwLock < bool > > ,
28
28
is_done : Arc < tokio:: sync:: RwLock < bool > > ,
29
29
rollback_savepoint : Arc < tokio:: sync:: RwLock < HashSet < String > > > ,
@@ -36,7 +36,7 @@ pub struct RustTransaction {
36
36
impl RustTransaction {
37
37
#[ allow( clippy:: too_many_arguments) ]
38
38
pub fn new (
39
- db_client : Arc < tokio :: sync :: RwLock < Object > > ,
39
+ db_client : Arc < Object > ,
40
40
is_started : Arc < tokio:: sync:: RwLock < bool > > ,
41
41
is_done : Arc < tokio:: sync:: RwLock < bool > > ,
42
42
rollback_savepoint : Arc < tokio:: sync:: RwLock < HashSet < String > > > ,
@@ -76,11 +76,8 @@ impl RustTransaction {
76
76
where
77
77
T : ValueOrReferenceTo < Vec < PythonDTO > > ,
78
78
{
79
- let db_client_arc = self . db_client . clone ( ) ;
80
79
let is_started_arc = self . is_started . clone ( ) ;
81
80
let is_done_arc = self . is_done . clone ( ) ;
82
-
83
- let db_client_guard = db_client_arc. read ( ) . await ;
84
81
let is_started_guard = is_started_arc. read ( ) . await ;
85
82
let is_done_guard = is_done_arc. read ( ) . await ;
86
83
@@ -101,9 +98,10 @@ impl RustTransaction {
101
98
vec_parameters. push ( param) ;
102
99
}
103
100
104
- let statement = db_client_guard . prepare_cached ( & querystring) . await ?;
101
+ let statement = self . db_client . prepare_cached ( & querystring) . await ?;
105
102
106
- let result = db_client_guard
103
+ let result = self
104
+ . db_client
107
105
. query ( & statement, & vec_parameters. into_boxed_slice ( ) )
108
106
. await ?;
109
107
@@ -133,11 +131,8 @@ impl RustTransaction {
133
131
where
134
132
T : ValueOrReferenceTo < Vec < PythonDTO > > ,
135
133
{
136
- let db_client_arc = self . db_client . clone ( ) ;
137
134
let is_started_arc = self . is_started . clone ( ) ;
138
135
let is_done_arc = self . is_done . clone ( ) ;
139
-
140
- let db_client_guard = db_client_arc. read ( ) . await ;
141
136
let is_started_guard = is_started_arc. read ( ) . await ;
142
137
let is_done_guard = is_done_arc. read ( ) . await ;
143
138
@@ -158,9 +153,10 @@ impl RustTransaction {
158
153
vec_parameters. push ( param) ;
159
154
}
160
155
161
- let statement = db_client_guard . prepare_cached ( & querystring) . await ?;
156
+ let statement = self . db_client . prepare_cached ( & querystring) . await ?;
162
157
163
- let result = db_client_guard
158
+ let result = self
159
+ . db_client
164
160
. query ( & statement, & vec_parameters. into_boxed_slice ( ) )
165
161
. await ?;
166
162
@@ -185,11 +181,8 @@ impl RustTransaction {
185
181
querystring : String ,
186
182
parameters : Vec < Vec < PythonDTO > > ,
187
183
) -> RustPSQLDriverPyResult < ( ) > {
188
- let db_client_arc = self . db_client . clone ( ) ;
189
184
let is_started_arc = self . is_started . clone ( ) ;
190
185
let is_done_arc = self . is_done . clone ( ) ;
191
-
192
- let db_client_guard = db_client_arc. read ( ) . await ;
193
186
let is_started_guard = is_started_arc. read ( ) . await ;
194
187
let is_done_guard = is_done_arc. read ( ) . await ;
195
188
@@ -209,8 +202,8 @@ impl RustTransaction {
209
202
) ) ;
210
203
}
211
204
for single_parameters in parameters {
212
- let statement = db_client_guard . prepare_cached ( & querystring) . await ?;
213
- db_client_guard
205
+ let statement = self . db_client . prepare_cached ( & querystring) . await ?;
206
+ self . db_client
214
207
. query (
215
208
& statement,
216
209
& single_parameters
@@ -243,11 +236,8 @@ impl RustTransaction {
243
236
querystring : String ,
244
237
parameters : Vec < PythonDTO > ,
245
238
) -> RustPSQLDriverPyResult < PSQLDriverSinglePyQueryResult > {
246
- let db_client_arc = self . db_client . clone ( ) ;
247
239
let is_started_arc = self . is_started . clone ( ) ;
248
240
let is_done_arc = self . is_done . clone ( ) ;
249
-
250
- let db_client_guard = db_client_arc. read ( ) . await ;
251
241
let is_started_guard = is_started_arc. read ( ) . await ;
252
242
let is_done_guard = is_done_arc. read ( ) . await ;
253
243
@@ -267,9 +257,10 @@ impl RustTransaction {
267
257
vec_parameters. push ( param) ;
268
258
}
269
259
270
- let statement = db_client_guard . prepare_cached ( & querystring) . await ?;
260
+ let statement = self . db_client . prepare_cached ( & querystring) . await ?;
271
261
272
- let result = db_client_guard
262
+ let result = self
263
+ . db_client
273
264
. query_one ( & statement, & vec_parameters. into_boxed_slice ( ) )
274
265
. await ?;
275
266
@@ -324,10 +315,7 @@ impl RustTransaction {
324
315
None => "" ,
325
316
} ) ;
326
317
327
- let db_client_arc = self . db_client . clone ( ) ;
328
- let db_client_guard = db_client_arc. read ( ) . await ;
329
-
330
- db_client_guard. batch_execute ( & querystring) . await ?;
318
+ self . db_client . batch_execute ( & querystring) . await ?;
331
319
332
320
Ok ( ( ) )
333
321
}
@@ -384,7 +372,6 @@ impl RustTransaction {
384
372
/// 2) Transaction is done
385
373
/// 3) Cannot execute `COMMIT` command
386
374
pub async fn inner_commit ( & self ) -> RustPSQLDriverPyResult < ( ) > {
387
- let db_client_arc = self . db_client . clone ( ) ;
388
375
let is_started_arc = self . is_started . clone ( ) ;
389
376
let is_done_arc = self . is_done . clone ( ) ;
390
377
@@ -407,9 +394,7 @@ impl RustTransaction {
407
394
"Transaction is already committed or rolled back" . into ( ) ,
408
395
) ) ;
409
396
}
410
-
411
- let db_client_guard = db_client_arc. read ( ) . await ;
412
- db_client_guard. batch_execute ( "COMMIT;" ) . await ?;
397
+ self . db_client . batch_execute ( "COMMIT;" ) . await ?;
413
398
let mut is_done_write_guard = is_done_arc. write ( ) . await ;
414
399
* is_done_write_guard = true ;
415
400
@@ -428,7 +413,6 @@ impl RustTransaction {
428
413
/// 3) Specified savepoint name is exists
429
414
/// 4) Can not execute SAVEPOINT command
430
415
pub async fn inner_savepoint ( & self , savepoint_name : String ) -> RustPSQLDriverPyResult < ( ) > {
431
- let db_client_arc = self . db_client . clone ( ) ;
432
416
let is_started_arc = self . is_started . clone ( ) ;
433
417
let is_done_arc = self . is_done . clone ( ) ;
434
418
@@ -462,9 +446,7 @@ impl RustTransaction {
462
446
"SAVEPOINT name {savepoint_name} is already taken by this transaction" ,
463
447
) ) ) ;
464
448
}
465
-
466
- let db_client_guard = db_client_arc. read ( ) . await ;
467
- db_client_guard
449
+ self . db_client
468
450
. batch_execute ( format ! ( "SAVEPOINT {savepoint_name}" ) . as_str ( ) )
469
451
. await ?;
470
452
let mut rollback_savepoint_guard = self . rollback_savepoint . write ( ) . await ;
@@ -504,10 +486,7 @@ impl RustTransaction {
504
486
"Transaction is already committed or rolled back" . into ( ) ,
505
487
) ) ;
506
488
} ;
507
-
508
- let db_client_arc = self . db_client . clone ( ) ;
509
- let db_client_guard = db_client_arc. read ( ) . await ;
510
- db_client_guard. batch_execute ( "ROLLBACK" ) . await ?;
489
+ self . db_client . batch_execute ( "ROLLBACK" ) . await ?;
511
490
let mut is_done_write_guard = is_done_arc. write ( ) . await ;
512
491
* is_done_write_guard = true ;
513
492
Ok ( ( ) )
@@ -556,10 +535,7 @@ impl RustTransaction {
556
535
"Don't have rollback with this name" . into ( ) ,
557
536
) ) ;
558
537
}
559
-
560
- let db_client_arc = self . db_client . clone ( ) ;
561
- let db_client_guard = db_client_arc. read ( ) . await ;
562
- db_client_guard
538
+ self . db_client
563
539
. batch_execute ( format ! ( "ROLLBACK TO SAVEPOINT {rollback_name}" ) . as_str ( ) )
564
540
. await ?;
565
541
@@ -610,10 +586,7 @@ impl RustTransaction {
610
586
"Don't have rollback with this name" . into ( ) ,
611
587
) ) ;
612
588
}
613
-
614
- let db_client_arc = self . db_client . clone ( ) ;
615
- let db_client_guard = db_client_arc. read ( ) . await ;
616
- db_client_guard
589
+ self . db_client
617
590
. batch_execute ( format ! ( "RELEASE SAVEPOINT {rollback_name}" ) . as_str ( ) )
618
591
. await ?;
619
592
0 commit comments