Line data Source code
1 : //! An asynchronous, pipelined, PostgreSQL client.
2 : #![warn(clippy::all)]
3 :
4 : use postgres_protocol2::message::backend::ReadyForQueryBody;
5 :
6 : pub use crate::cancel_token::CancelToken;
7 : pub use crate::client::{Client, SocketConfig};
8 : pub use crate::config::Config;
9 : pub use crate::connect_raw::RawConnection;
10 : pub use crate::connection::Connection;
11 : use crate::error::DbError;
12 : pub use crate::error::Error;
13 : pub use crate::generic_client::GenericClient;
14 : pub use crate::query::RowStream;
15 : pub use crate::row::{Row, SimpleQueryRow};
16 : pub use crate::simple_query::SimpleQueryStream;
17 : pub use crate::statement::{Column, Statement};
18 : pub use crate::tls::NoTls;
19 : pub use crate::transaction::Transaction;
20 : pub use crate::transaction_builder::{IsolationLevel, TransactionBuilder};
21 : use crate::types::ToSql;
22 :
23 : /// After executing a query, the connection will be in one of these states
24 : #[derive(Clone, Copy, Debug, PartialEq)]
25 : #[repr(u8)]
26 : pub enum ReadyForQueryStatus {
27 : /// Connection state is unknown
28 : Unknown,
29 : /// Connection is idle (no transactions)
30 : Idle = b'I',
31 : /// Connection is in a transaction block
32 : Transaction = b'T',
33 : /// Connection is in a failed transaction block
34 : FailedTransaction = b'E',
35 : }
36 :
37 : impl From<ReadyForQueryBody> for ReadyForQueryStatus {
38 0 : fn from(value: ReadyForQueryBody) -> Self {
39 0 : match value.status() {
40 0 : b'I' => Self::Idle,
41 0 : b'T' => Self::Transaction,
42 0 : b'E' => Self::FailedTransaction,
43 0 : _ => Self::Unknown,
44 : }
45 0 : }
46 : }
47 :
48 : mod cancel_query;
49 : mod cancel_query_raw;
50 : mod cancel_token;
51 : mod client;
52 : mod codec;
53 : pub mod config;
54 : mod connect;
55 : mod connect_raw;
56 : mod connect_socket;
57 : mod connect_tls;
58 : mod connection;
59 : pub mod error;
60 : mod generic_client;
61 : pub mod maybe_tls_stream;
62 : mod prepare;
63 : mod query;
64 : pub mod row;
65 : mod simple_query;
66 : mod statement;
67 : pub mod tls;
68 : mod transaction;
69 : mod transaction_builder;
70 : pub mod types;
71 :
72 : /// An asynchronous notification.
73 : #[derive(Clone, Debug)]
74 : pub struct Notification {
75 : process_id: i32,
76 : channel: String,
77 : payload: String,
78 : }
79 :
80 : impl Notification {
81 : /// The process ID of the notifying backend process.
82 0 : pub fn process_id(&self) -> i32 {
83 0 : self.process_id
84 0 : }
85 :
86 : /// The name of the channel that the notify has been raised on.
87 0 : pub fn channel(&self) -> &str {
88 0 : &self.channel
89 0 : }
90 :
91 : /// The "payload" string passed from the notifying process.
92 0 : pub fn payload(&self) -> &str {
93 0 : &self.payload
94 0 : }
95 : }
96 :
97 : /// An asynchronous message from the server.
98 : #[allow(clippy::large_enum_variant)]
99 : #[derive(Debug, Clone)]
100 : #[non_exhaustive]
101 : pub enum AsyncMessage {
102 : /// A notice.
103 : ///
104 : /// Notices use the same format as errors, but aren't "errors" per-se.
105 : Notice(DbError),
106 : /// A notification.
107 : ///
108 : /// Connections can subscribe to notifications with the `LISTEN` command.
109 : Notification(Notification),
110 : }
111 :
112 : /// Message returned by the `SimpleQuery` stream.
113 : #[derive(Debug)]
114 : #[non_exhaustive]
115 : pub enum SimpleQueryMessage {
116 : /// A row of data.
117 : Row(SimpleQueryRow),
118 : /// A statement in the query has completed.
119 : ///
120 : /// The number of rows modified or selected is returned.
121 : CommandComplete(u64),
122 : }
123 :
124 0 : fn slice_iter<'a>(
125 0 : s: &'a [&'a (dyn ToSql + Sync)],
126 0 : ) -> impl ExactSizeIterator<Item = &'a (dyn ToSql + Sync)> + 'a {
127 0 : s.iter().map(|s| *s as _)
128 0 : }
|