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, RawCancelToken};
7 : pub use crate::client::{Client, SocketConfig};
8 : pub use crate::config::Config;
9 : pub use crate::connection::Connection;
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 :
20 : /// After executing a query, the connection will be in one of these states
21 : #[derive(Clone, Copy, Debug, PartialEq)]
22 : #[repr(u8)]
23 : pub enum ReadyForQueryStatus {
24 : /// Connection state is unknown
25 : Unknown,
26 : /// Connection is idle (no transactions)
27 : Idle = b'I',
28 : /// Connection is in a transaction block
29 : Transaction = b'T',
30 : /// Connection is in a failed transaction block
31 : FailedTransaction = b'E',
32 : }
33 :
34 : impl From<ReadyForQueryBody> for ReadyForQueryStatus {
35 0 : fn from(value: ReadyForQueryBody) -> Self {
36 0 : match value.status() {
37 0 : b'I' => Self::Idle,
38 0 : b'T' => Self::Transaction,
39 0 : b'E' => Self::FailedTransaction,
40 0 : _ => Self::Unknown,
41 : }
42 0 : }
43 : }
44 :
45 : mod cancel_query;
46 : mod cancel_query_raw;
47 : mod cancel_token;
48 : mod client;
49 : mod codec;
50 : pub mod config;
51 : pub mod connect;
52 : pub mod connect_raw;
53 : mod connect_socket;
54 : mod connect_tls;
55 : mod connection;
56 : pub mod error;
57 : mod generic_client;
58 : pub mod maybe_tls_stream;
59 : mod prepare;
60 : mod query;
61 : pub mod row;
62 : mod simple_query;
63 : mod statement;
64 : pub mod tls;
65 : mod transaction;
66 : mod transaction_builder;
67 : pub mod types;
68 :
69 : /// An asynchronous notification.
70 : #[derive(Clone, Debug)]
71 : pub struct Notification {
72 : process_id: i32,
73 : channel: String,
74 : payload: String,
75 : }
76 :
77 : impl Notification {
78 : /// The process ID of the notifying backend process.
79 0 : pub fn process_id(&self) -> i32 {
80 0 : self.process_id
81 0 : }
82 :
83 : /// The name of the channel that the notify has been raised on.
84 0 : pub fn channel(&self) -> &str {
85 0 : &self.channel
86 0 : }
87 :
88 : /// The "payload" string passed from the notifying process.
89 0 : pub fn payload(&self) -> &str {
90 0 : &self.payload
91 0 : }
92 : }
93 :
94 : /// Message returned by the `SimpleQuery` stream.
95 : #[derive(Debug)]
96 : #[non_exhaustive]
97 : pub enum SimpleQueryMessage {
98 : /// A row of data.
99 : Row(SimpleQueryRow),
100 : /// A statement in the query has completed.
101 : ///
102 : /// The number of rows modified or selected is returned.
103 : CommandComplete(u64),
104 : }
|