@@ -19,7 +19,7 @@ use crate::{
19
19
use bytes:: { Buf , BytesMut } ;
20
20
use fallible_iterator:: FallibleIterator ;
21
21
use futures_channel:: mpsc;
22
- use futures_util:: { pin_mut , StreamExt , TryStreamExt } ;
22
+ use futures_util:: { StreamExt , TryStreamExt } ;
23
23
use parking_lot:: Mutex ;
24
24
use postgres_protocol:: message:: backend:: Message ;
25
25
use postgres_protocol:: message:: frontend;
@@ -323,70 +323,6 @@ impl Client {
323
323
Ok ( first)
324
324
}
325
325
326
- /// Like `query_one`, but requires the types of query parameters to be explicitly specified.
327
- ///
328
- /// Compared to `query_one`, this method allows performing queries without three round trips (for
329
- /// prepare, execute, and close) by requiring the caller to specify parameter values along with
330
- /// their Postgres type. Thus, this is suitable in environments where prepared statements aren't
331
- /// supported (such as Cloudflare Workers with Hyperdrive).
332
- ///
333
- /// Executes a statement which returns a single row, returning it.
334
- ///
335
- /// Returns an error if the query does not return exactly one row.
336
- ///
337
- /// A statement may contain parameters, specified by `$n`, where `n` is the index of the parameter of the list
338
- /// provided, 1-indexed.
339
- ///
340
- pub async fn query_typed_one (
341
- & self ,
342
- statement : & str ,
343
- params : & [ ( & ( dyn ToSql +Sync ) , Type ) ] ,
344
- ) ->Result < Row , Error > {
345
- self . query_typed_opt ( statement, params)
346
- . await
347
- . and_then ( |res| res. ok_or_else ( Error :: row_count) )
348
- }
349
-
350
- /// Like `query_one`, but requires the types of query parameters to be explicitly specified.
351
- ///
352
- /// Compared to `query_one`, this method allows performing queries without three round trips (for
353
- /// prepare, execute, and close) by requiring the caller to specify parameter values along with
354
- /// their Postgres type. Thus, this is suitable in environments where prepared statements aren't
355
- /// supported (such as Cloudflare Workers with Hyperdrive).
356
- ///
357
- /// A statement may contain parameters, specified by `$n`, where `n` is the index of the
358
- /// parameter of the list provided, 1-indexed.
359
- /// Executes a statements which returns zero or one rows, returning it.
360
- ///
361
- /// Returns an error if the query returns more than one row.
362
- pub async fn query_typed_opt (
363
- & self ,
364
- statement : & str ,
365
- params : & [ ( & ( dyn ToSql +Sync ) , Type ) ] ,
366
- ) ->Result < Option < Row > , Error > {
367
- let stream =self
368
- . query_typed_raw ( statement, params. iter ( ) . map ( |( v, t) |( * v, t. clone ( ) ) ) )
369
- . await ?;
370
- pin_mut ! ( stream) ;
371
-
372
- let mut first =None ;
373
-
374
- // Originally this was two calls to `try_next().await?`,
375
- // once for the first element, and second to error if more than one.
376
- //
377
- // However, this new form with only one .await in a loop generates
378
- // slightly smaller codegen/stack usage for the resulting future.
379
- while let Some ( row) = stream. try_next ( ) . await ?{
380
- if first. is_some ( ) {
381
- return Err ( Error :: row_count ( ) ) ;
382
- }
383
-
384
- first =Some ( row) ;
385
- }
386
-
387
- Ok ( first)
388
- }
389
-
390
326
/// The maximally flexible version of [`query`].
391
327
///
392
328
/// A statement may contain parameters, specified by `$n`, where `n` is the index of the parameter of the list
@@ -452,6 +388,70 @@ impl Client {
452
388
. await
453
389
}
454
390
391
+ /// Like `query_one`, but requires the types of query parameters to be explicitly specified.
392
+ ///
393
+ /// Compared to `query_one`, this method allows performing queries without three round trips (for
394
+ /// prepare, execute, and close) by requiring the caller to specify parameter values along with
395
+ /// their Postgres type. Thus, this is suitable in environments where prepared statements aren't
396
+ /// supported (such as Cloudflare Workers with Hyperdrive).
397
+ ///
398
+ /// Executes a statement which returns a single row, returning it.
399
+ ///
400
+ /// Returns an error if the query does not return exactly one row.
401
+ ///
402
+ /// A statement may contain parameters, specified by `$n`, where `n` is the index of the parameter of the list
403
+ /// provided, 1-indexed.
404
+ ///
405
+ pub async fn query_typed_one (
406
+ & self ,
407
+ statement : & str ,
408
+ params : & [ ( & ( dyn ToSql +Sync ) , Type ) ] ,
409
+ ) ->Result < Row , Error > {
410
+ self . query_typed_opt ( statement, params)
411
+ . await
412
+ . and_then ( |res| res. ok_or_else ( Error :: row_count) )
413
+ }
414
+
415
+ /// Like `query_one`, but requires the types of query parameters to be explicitly specified.
416
+ ///
417
+ /// Compared to `query_one`, this method allows performing queries without three round trips (for
418
+ /// prepare, execute, and close) by requiring the caller to specify parameter values along with
419
+ /// their Postgres type. Thus, this is suitable in environments where prepared statements aren't
420
+ /// supported (such as Cloudflare Workers with Hyperdrive).
421
+ ///
422
+ /// A statement may contain parameters, specified by `$n`, where `n` is the index of the
423
+ /// parameter of the list provided, 1-indexed.
424
+ /// Executes a statements which returns zero or one rows, returning it.
425
+ ///
426
+ /// Returns an error if the query returns more than one row.
427
+ pub async fn query_typed_opt (
428
+ & self ,
429
+ statement : & str ,
430
+ params : & [ ( & ( dyn ToSql +Sync ) , Type ) ] ,
431
+ ) ->Result < Option < Row > , Error > {
432
+ let mut stream =pin ! (
433
+ self . query_typed_raw( statement, params. iter( ) . map( |( v, t) |( * v, t. clone( ) ) ) )
434
+ . await ?
435
+ ) ;
436
+
437
+ let mut first =None ;
438
+
439
+ // Originally this was two calls to `try_next().await?`,
440
+ // once for the first element, and second to error if more than one.
441
+ //
442
+ // However, this new form with only one .await in a loop generates
443
+ // slightly smaller codegen/stack usage for the resulting future.
444
+ while let Some ( row) = stream. try_next ( ) . await ?{
445
+ if first. is_some ( ) {
446
+ return Err ( Error :: row_count ( ) ) ;
447
+ }
448
+
449
+ first =Some ( row) ;
450
+ }
451
+
452
+ Ok ( first)
453
+ }
454
+
455
455
/// The maximally flexible version of [`query_typed`].
456
456
///
457
457
/// Compared to `query`, this method allows performing queries without three round trips (for