@@ -110,6 +110,7 @@ impl Connection for SingleConnection {
110110}
111111
112112impl StartTransaction for SingleConnection {
113+ #[ allow( clippy:: used_underscore_items) ]
113114 async fn start_transaction (
114115 & mut self ,
115116 isolation_level : Option < IsolationLevel > ,
@@ -125,13 +126,15 @@ impl StartTransaction for SingleConnection {
125126}
126127
127128impl CloseTransaction for SingleConnection {
129+ #[ allow( clippy:: used_underscore_items) ]
128130 async fn commit ( & mut self ) -> PSQLPyResult < ( ) > {
129131 self . _commit ( ) . await ?;
130132 self . in_transaction = false ;
131133
132134 Ok ( ( ) )
133135 }
134136
137+ #[ allow( clippy:: used_underscore_items) ]
135138 async fn rollback ( & mut self ) -> PSQLPyResult < ( ) > {
136139 self . _rollback ( ) . await ?;
137140 self . in_transaction = false ;
@@ -193,6 +196,7 @@ impl Connection for PoolConnection {
193196}
194197
195198impl StartTransaction for PoolConnection {
199+ #[ allow( clippy:: used_underscore_items) ]
196200 async fn start_transaction (
197201 & mut self ,
198202 isolation_level : Option < IsolationLevel > ,
@@ -206,13 +210,15 @@ impl StartTransaction for PoolConnection {
206210}
207211
208212impl CloseTransaction for PoolConnection {
213+ #[ allow( clippy:: used_underscore_items) ]
209214 async fn commit ( & mut self ) -> PSQLPyResult < ( ) > {
210215 self . _commit ( ) . await ?;
211216 self . in_transaction = false ;
212217
213218 Ok ( ( ) )
214219 }
215220
221+ #[ allow( clippy:: used_underscore_items) ]
216222 async fn rollback ( & mut self ) -> PSQLPyResult < ( ) > {
217223 self . _rollback ( ) . await ?;
218224 self . in_transaction = false ;
@@ -324,13 +330,18 @@ impl CloseTransaction for PSQLPyConnection {
324330}
325331
326332impl PSQLPyConnection {
333+ #[ must_use]
327334 pub fn in_transaction ( & self ) -> bool {
328335 match self {
329336 PSQLPyConnection :: PoolConn ( conn) => conn. in_transaction ,
330337 PSQLPyConnection :: SingleConnection ( conn) => conn. in_transaction ,
331338 }
332339 }
333340
341+ /// Prepare internal `PSQLPy` statement
342+ ///
343+ /// # Errors
344+ /// May return error if there is some problem with DB communication.
334345 pub async fn prepare_statement (
335346 & self ,
336347 querystring : String ,
@@ -341,6 +352,10 @@ impl PSQLPyConnection {
341352 . await
342353 }
343354
355+ /// Execute prepared `PSQLPy` statement.
356+ ///
357+ /// # Errors
358+ /// May return error if there is some problem with DB communication.
344359 pub async fn execute_statement (
345360 & self ,
346361 statement : & PsqlpyStatement ,
@@ -352,6 +367,10 @@ impl PSQLPyConnection {
352367 Ok ( PSQLDriverPyQueryResult :: new ( result) )
353368 }
354369
370+ /// Execute raw query with parameters.
371+ ///
372+ /// # Errors
373+ /// May return error if there is some problem with DB communication.
355374 pub async fn execute (
356375 & self ,
357376 querystring : String ,
@@ -363,15 +382,12 @@ impl PSQLPyConnection {
363382 . await ?;
364383
365384 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
375391 } ;
376392
377393 let return_result = result. map_err ( |err| {
@@ -383,6 +399,10 @@ impl PSQLPyConnection {
383399 Ok ( PSQLDriverPyQueryResult :: new ( return_result) )
384400 }
385401
402+ /// Execute many queries without return.
403+ ///
404+ /// # Errors
405+ /// May return error if there is some problem with DB communication.
386406 pub async fn execute_many (
387407 & self ,
388408 querystring : String ,
@@ -431,6 +451,11 @@ impl PSQLPyConnection {
431451 Ok ( ( ) )
432452 }
433453
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.
434459 pub async fn fetch_row_raw (
435460 & self ,
436461 querystring : String ,
@@ -466,6 +491,11 @@ impl PSQLPyConnection {
466491 Ok ( result)
467492 }
468493
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.
469499 pub async fn fetch_row (
470500 & self ,
471501 querystring : String ,
@@ -479,6 +509,11 @@ impl PSQLPyConnection {
479509 Ok ( PSQLDriverSinglePyQueryResult :: new ( result) )
480510 }
481511
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.
482517 pub async fn fetch_val (
483518 & self ,
484519 querystring : String ,
@@ -495,6 +530,11 @@ impl PSQLPyConnection {
495530 } )
496531 }
497532
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.
498538 pub async fn copy_in < T , U > ( & self , statement : & T ) -> PSQLPyResult < CopyInSink < U > >
499539 where
500540 T : ?Sized + ToStatement ,
@@ -510,6 +550,14 @@ impl PSQLPyConnection {
510550 }
511551 }
512552
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.
513561 pub async fn transaction ( & mut self ) -> PSQLPyResult < PSQLPyTransaction > {
514562 match self {
515563 PSQLPyConnection :: PoolConn ( conn) => {
@@ -531,33 +579,33 @@ impl PSQLPyConnection {
531579 }
532580 }
533581
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.
534587 pub async fn portal (
535588 & mut self ,
536589 querystring : Option < & String > ,
537590 parameters : & Option < pyo3:: Py < PyAny > > ,
538591 statement : Option < & PsqlpyStatement > ,
539592 ) -> 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 ?
555605 } ;
556606
557607 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 ?;
561609
562610 Ok ( ( transaction, inner_portal) )
563611 }
0 commit comments