tokio_postgres/
portal.rs

1use crate::client::InnerClient;
2use crate::codec::FrontendMessage;
3use crate::connection::RequestMessages;
4use crate::Statement;
5use postgres_protocol::message::frontend;
6use std::sync::{Arc, Weak};
7
8struct Inner {
9    client: Weak<InnerClient>,
10    name: String,
11    statement: Statement,
12}
13
14impl Drop for Inner {
15    fn drop(&mut self) {
16        if let Some(client) = self.client.upgrade() {
17            let buf = client.with_buf(|buf| {
18                frontend::close(b'P', &self.name, buf).unwrap();
19                frontend::sync(buf);
20                buf.split().freeze()
21            });
22            let _ = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)));
23        }
24    }
25}
26
27/// A portal.
28///
29/// Portals can only be used with the connection that created them, and only exist for the duration of the transaction
30/// in which they were created.
31#[derive(Clone)]
32pub struct Portal(Arc<Inner>);
33
34impl Portal {
35    pub(crate) fn new(client: &Arc<InnerClient>, name: String, statement: Statement) -> Portal {
36        Portal(Arc::new(Inner {
37            client: Arc::downgrade(client),
38            name,
39            statement,
40        }))
41    }
42
43    pub(crate) fn name(&self) -> &str {
44        &self.0.name
45    }
46
47    pub(crate) fn statement(&self) -> &Statement {
48        &self.0.statement
49    }
50}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy