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