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