@@ -110,6 +110,7 @@ impl Connection for SingleConnection {
110
110
}
111
111
112
112
impl StartTransaction for SingleConnection {
113
+ #[ allow( clippy:: used_underscore_items) ]
113
114
async fn start_transaction (
114
115
& mut self ,
115
116
isolation_level : Option < IsolationLevel > ,
@@ -125,13 +126,15 @@ impl StartTransaction for SingleConnection {
125
126
}
126
127
127
128
impl CloseTransaction for SingleConnection {
129
+ #[ allow( clippy:: used_underscore_items) ]
128
130
async fn commit ( & mut self ) -> PSQLPyResult < ( ) > {
129
131
self . _commit ( ) . await ?;
130
132
self . in_transaction = false ;
131
133
132
134
Ok ( ( ) )
133
135
}
134
136
137
+ #[ allow( clippy:: used_underscore_items) ]
135
138
async fn rollback ( & mut self ) -> PSQLPyResult < ( ) > {
136
139
self . _rollback ( ) . await ?;
137
140
self . in_transaction = false ;
@@ -193,6 +196,7 @@ impl Connection for PoolConnection {
193
196
}
194
197
195
198
impl StartTransaction for PoolConnection {
199
+ #[ allow( clippy:: used_underscore_items) ]
196
200
async fn start_transaction (
197
201
& mut self ,
198
202
isolation_level : Option < IsolationLevel > ,
@@ -206,13 +210,15 @@ impl StartTransaction for PoolConnection {
206
210
}
207
211
208
212
impl CloseTransaction for PoolConnection {
213
+ #[ allow( clippy:: used_underscore_items) ]
209
214
async fn commit ( & mut self ) -> PSQLPyResult < ( ) > {
210
215
self . _commit ( ) . await ?;
211
216
self . in_transaction = false ;
212
217
213
218
Ok ( ( ) )
214
219
}
215
220
221
+ #[ allow( clippy:: used_underscore_items) ]
216
222
async fn rollback ( & mut self ) -> PSQLPyResult < ( ) > {
217
223
self . _rollback ( ) . await ?;
218
224
self . in_transaction = false ;
@@ -324,13 +330,18 @@ impl CloseTransaction for PSQLPyConnection {
324
330
}
325
331
326
332
impl PSQLPyConnection {
333
+ #[ must_use]
327
334
pub fn in_transaction ( & self ) -> bool {
328
335
match self {
329
336
PSQLPyConnection :: PoolConn ( conn) => conn. in_transaction ,
330
337
PSQLPyConnection :: SingleConnection ( conn) => conn. in_transaction ,
331
338
}
332
339
}
333
340
341
+ /// Prepare internal `PSQLPy` statement
342
+ ///
343
+ /// # Errors
344
+ /// May return error if there is some problem with DB communication.
334
345
pub async fn prepare_statement (
335
346
& self ,
336
347
querystring : String ,
@@ -341,6 +352,10 @@ impl PSQLPyConnection {
341
352
. await
342
353
}
343
354
355
+ /// Execute prepared `PSQLPy` statement.
356
+ ///
357
+ /// # Errors
358
+ /// May return error if there is some problem with DB communication.
344
359
pub async fn execute_statement (
345
360
& self ,
346
361
statement : & PsqlpyStatement ,
@@ -352,6 +367,10 @@ impl PSQLPyConnection {
352
367
Ok ( PSQLDriverPyQueryResult :: new ( result) )
353
368
}
354
369
370
+ /// Execute raw query with parameters.
371
+ ///
372
+ /// # Errors
373
+ /// May return error if there is some problem with DB communication.
355
374
pub async fn execute (
356
375
& self ,
357
376
querystring : String ,
@@ -363,15 +382,12 @@ impl PSQLPyConnection {
363
382
. await ?;
364
383
365
384
let prepared = prepared. unwrap_or ( true ) ;
366
- let result = match prepared {
367
- true => {
368
- self . query ( statement. statement_query ( ) ?, & statement. params ( ) )
369
- . await
370
- }
371
- false => {
372
- self . query_typed ( statement. raw_query ( ) , & statement. params_typed ( ) )
373
- . await
374
- }
385
+ let result = if prepared {
386
+ self . query ( statement. statement_query ( ) ?, & statement. params ( ) )
387
+ . await
388
+ } else {
389
+ self . query_typed ( statement. raw_query ( ) , & statement. params_typed ( ) )
390
+ . await
375
391
} ;
376
392
377
393
let return_result = result. map_err ( |err| {
@@ -383,6 +399,10 @@ impl PSQLPyConnection {
383
399
Ok ( PSQLDriverPyQueryResult :: new ( return_result) )
384
400
}
385
401
402
+ /// Execute many queries without return.
403
+ ///
404
+ /// # Errors
405
+ /// May return error if there is some problem with DB communication.
386
406
pub async fn execute_many (
387
407
& self ,
388
408
querystring : String ,
@@ -431,6 +451,11 @@ impl PSQLPyConnection {
431
451
Ok ( ( ) )
432
452
}
433
453
454
+ /// Execute raw query with parameters. Return one raw row
455
+ ///
456
+ /// # Errors
457
+ /// May return error if there is some problem with DB communication.
458
+ /// Or if cannot build statement.
434
459
pub async fn fetch_row_raw (
435
460
& self ,
436
461
querystring : String ,
@@ -466,6 +491,11 @@ impl PSQLPyConnection {
466
491
Ok ( result)
467
492
}
468
493
494
+ /// Execute raw query with parameters. Return one row
495
+ ///
496
+ /// # Errors
497
+ /// May return error if there is some problem with DB communication.
498
+ /// Or if cannot build statement.
469
499
pub async fn fetch_row (
470
500
& self ,
471
501
querystring : String ,
@@ -479,6 +509,11 @@ impl PSQLPyConnection {
479
509
Ok ( PSQLDriverSinglePyQueryResult :: new ( result) )
480
510
}
481
511
512
+ /// Execute raw query with parameters. Return single python object
513
+ ///
514
+ /// # Errors
515
+ /// May return error if there is some problem with DB communication.
516
+ /// Or if cannot build statement.
482
517
pub async fn fetch_val (
483
518
& self ,
484
519
querystring : String ,
@@ -495,6 +530,11 @@ impl PSQLPyConnection {
495
530
} )
496
531
}
497
532
533
+ /// Create new sink for COPY operation.
534
+ ///
535
+ /// # Errors
536
+ /// May return error if there is some problem with DB communication.
537
+ /// Or if cannot build statement.
498
538
pub async fn copy_in < T , U > ( & self , statement : & T ) -> PSQLPyResult < CopyInSink < U > >
499
539
where
500
540
T : ?Sized + ToStatement ,
@@ -510,6 +550,14 @@ impl PSQLPyConnection {
510
550
}
511
551
}
512
552
553
+ /// Create and open new transaction.
554
+ ///
555
+ /// Unsafe here isn't a problem cuz it is stored within
556
+ /// the struct with the connection created this transaction.
557
+ ///
558
+ /// # Errors
559
+ /// May return error if there is some problem with DB communication.
560
+ /// Or if cannot build statement.
513
561
pub async fn transaction ( & mut self ) -> PSQLPyResult < PSQLPyTransaction > {
514
562
match self {
515
563
PSQLPyConnection :: PoolConn ( conn) => {
@@ -531,33 +579,33 @@ impl PSQLPyConnection {
531
579
}
532
580
}
533
581
582
+ /// Create new Portal (server-side byte cursor).
583
+ ///
584
+ /// # Errors
585
+ /// May return error if there is some problem with DB communication.
586
+ /// Or if cannot build statement.
534
587
pub async fn portal (
535
588
& mut self ,
536
589
querystring : Option < & String > ,
537
590
parameters : & Option < pyo3:: Py < PyAny > > ,
538
591
statement : Option < & PsqlpyStatement > ,
539
592
) -> PSQLPyResult < ( PSQLPyTransaction , tp_Portal ) > {
540
- let statement = {
541
- match statement {
542
- Some ( stmt) => stmt,
543
- None => {
544
- let Some ( querystring) = querystring else {
545
- return Err ( RustPSQLDriverError :: ConnectionExecuteError (
546
- "Can't create cursor without querystring" . into ( ) ,
547
- ) ) ;
548
- } ;
549
-
550
- & StatementBuilder :: new ( querystring, parameters, self , Some ( false ) )
551
- . build ( )
552
- . await ?
553
- }
554
- }
593
+ let stmt = if let Some ( stmt) = statement {
594
+ stmt
595
+ } else {
596
+ let Some ( querystring) = querystring else {
597
+ return Err ( RustPSQLDriverError :: ConnectionExecuteError (
598
+ "Can't create cursor without querystring" . into ( ) ,
599
+ ) ) ;
600
+ } ;
601
+
602
+ & StatementBuilder :: new ( querystring, parameters, self , Some ( false ) )
603
+ . build ( )
604
+ . await ?
555
605
} ;
556
606
557
607
let transaction = self . transaction ( ) . await ?;
558
- let inner_portal = transaction
559
- . portal ( statement. raw_query ( ) , & statement. params ( ) )
560
- . await ?;
608
+ let inner_portal = transaction. portal ( stmt. raw_query ( ) , & stmt. params ( ) ) . await ?;
561
609
562
610
Ok ( ( transaction, inner_portal) )
563
611
}
0 commit comments