xitca_postgres/
query.rs

1mod stream;
2
3#[cfg(feature = "compat")]
4pub(crate) mod compat;
5
6pub use stream::{RowAffected, RowSimpleStream, RowSimpleStreamOwned, RowStream, RowStreamGuarded, RowStreamOwned};
7
8use super::{
9    driver::codec::{encode::Encode, response::IntoResponse, Response},
10    error::Error,
11};
12
13/// trait generic over api used for querying with typed prepared statement.
14///
15/// types like [Transaction] and [CopyIn] accept generic client type and they are able to use user supplied
16/// client new type to operate and therefore reduce less new types and methods boilerplate.
17///
18/// [Transaction]: crate::transaction::Transaction
19/// [CopyIn]: crate::copy::CopyIn
20pub trait Query {
21    /// query with statement and dynamic typed params.
22    ///
23    /// statement must be a type impl [`Encode`] trait
24    #[inline]
25    fn _query<S>(&self, stmt: S) -> Result<<S::Output as IntoResponse>::Response, Error>
26    where
27        S: Encode,
28    {
29        self._send_encode_query(stmt)
30            .map(|(stream, res)| stream.into_response(res))
31    }
32
33    /// encode statement and params and send it to client driver
34    fn _send_encode_query<S>(&self, stmt: S) -> Result<(S::Output, Response), Error>
35    where
36        S: Encode;
37}