Skip to content

Commit 011615a

Browse files
authored
Update mod.rs
1 parent 72036e4 commit 011615a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/pg/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ use diesel::pg::{
1616
};
1717
use diesel::query_builder::bind_collector::RawBytesBindCollector;
1818
use diesel::query_builder::{AsQuery, QueryBuilder, QueryFragment, QueryId};
19-
use diesel::result::DatabaseErrorKind;
19+
use diesel::result::{DatabaseErrorKind, Error};
2020
use diesel::{ConnectionError, ConnectionResult, QueryResult};
2121
use futures_util::future::BoxFuture;
2222
use futures_util::future::Either;
2323
use futures_util::stream::{BoxStream, TryStreamExt};
2424
use futures_util::TryFutureExt;
2525
use futures_util::{Future, FutureExt, StreamExt};
26-
use std::borrow::Cow;
2726
use std::collections::HashMap;
2827
use std::sync::Arc;
2928
use tokio::sync::broadcast;
@@ -432,6 +431,7 @@ impl AsyncPgConnection {
432431
PgTypeMetadata::from_result(Ok(type_metadata))
433432
};
434433
let (fake_oid, fake_array_oid) = metadata_lookup.fake_oids(index);
434+
let [real_oid, real_array_oid] = unwrap_oids(&real_metadata);
435435
real_oids.extend([
436436
(fake_oid, real_metadata.oid()?),
437437
(fake_array_oid, real_metadata.array_oid()?),
@@ -440,7 +440,7 @@ impl AsyncPgConnection {
440440

441441
// Replace fake OIDs with real OIDs in `bind_collector.metadata`
442442
for m in &mut bind_collector.metadata {
443-
let [oid, array_oid] = [m.oid()?, m.array_oid()?]
443+
let [oid, array_oid] = unwrap_oids(&m)
444444
.map(|oid| {
445445
real_oids
446446
.get(&oid)
@@ -453,8 +453,8 @@ impl AsyncPgConnection {
453453
*m = PgTypeMetadata::new(oid, array_oid);
454454
}
455455
// Replace fake OIDs with real OIDs in `bind_collector.binds`
456-
for location in fake_oid_locations {
457-
replace_fake_oid(&mut bind_collector.binds, &real_oids, location)
456+
for (bind_index, byte_index) in fake_oid_locations {
457+
replace_fake_oid(&mut bind_collector.binds, &real_oids, bind_index, byte_index)
458458
.ok_or_else(|| {
459459
Error::SerializationError(
460460
format!("diesel_async failed to replace a type OID serialized in bind value {bind_index}").into(),
@@ -577,10 +577,16 @@ async fn lookup_type(
577577
Ok((r.get(0), r.get(1)))
578578
}
579579

580+
fn unwrap_oids(metadata: &PgTypeMetadata) -> [u32; 2] {
581+
[metadata.oid(), metadata.array_oid()]
582+
.map(|oid| oid.expect("PgTypeMetadata is supposed to always be Ok here"))
583+
}
584+
580585
fn replace_fake_oid(
581586
binds: &mut [Option<Vec<u8>>],
582-
real_oids: HashMap<u32, u32>,
583-
(bind_index, byte_index): (usize, usize),
587+
real_oids: &HashMap<u32, u32>,
588+
bind_index: usize,
589+
byte_index: usize,
584590
) -> Option<()> {
585591
let serialized_oid = binds
586592
.get_mut(bind_index)?

0 commit comments

Comments
 (0)