Skip to content

Commit 75e3193

Browse files
committed
sqlx-postgres: Add comments
1 parent f5a204f commit 75e3193

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

sqlx-postgres/src/connection/establish.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use super::worker::{Shared, Worker};
1212

1313
impl PgConnection {
1414
pub(crate) async fn establish(options: &PgConnectOptions) -> Result<Self, Error> {
15+
// A channel to communicate postgres notifications between the bg worker and a `PgListener`.
1516
let (notif_tx, notif_rx) = unbounded();
17+
18+
// Shared state between the bg worker and the `PgConnection`
1619
let shared = Shared::new();
1720

1821
// Upgrade to TLS if we were asked to and the server supports it
@@ -116,7 +119,7 @@ impl PgConnection {
116119
}
117120

118121
BackendMessageFormat::ReadyForQuery => {
119-
// Transaction status is updated in the bg worker.
122+
// The transaction status is updated in the bg worker.
120123
break;
121124
}
122125

sqlx-postgres/src/connection/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct PgConnection {
4040
}
4141

4242
pub struct PgConnectionInner {
43+
// channel to the background worker
4344
chan: UnboundedSender<IoRequest>,
4445

4546
pub(crate) notifications: UnboundedReceiver<Notification>,

sqlx-postgres/src/connection/pipe.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::{
77
PgDatabaseError,
88
};
99

10+
/// A temporary stream of responses sent from the background worker. The steam is stopped when
11+
/// either a [ReadyForQuery] of [CopyInResponse] is received.
1012
pub struct Pipe {
1113
receiver: UnboundedReceiver<ReceivedMessage>,
1214
}
@@ -21,6 +23,7 @@ impl Pipe {
2123
}
2224

2325
pub async fn recv_ready_for_query(&mut self) -> Result<(), Error> {
26+
// The transaction status is updated in the bg worker.
2427
let _: ReadyForQuery = self.recv_expect().await?;
2528
Ok(())
2629
}
@@ -30,7 +33,7 @@ impl Pipe {
3033
let message = self.recv().await?;
3134

3235
if let BackendMessageFormat::ReadyForQuery = message.format {
33-
let _: ReadyForQuery = message.decode()?;
36+
// The transaction status is updated in the bg worker.
3437
break;
3538
}
3639
}

sqlx-postgres/src/connection/request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct IoRequest {
1010
pub data: Vec<u8>,
1111
}
1212

13+
/// A buffer that contains encoded postgres messages, ready to be sent over the wire.
1314
pub struct MessageBuf {
1415
data: Vec<u8>,
1516
}

0 commit comments

Comments
 (0)