xitca_postgres/
execute.rs

1mod async_impl;
2mod sync_impl;
3
4/// Defining how a query is executed. can be used for customizing encoding, executing and database
5/// data decoding.
6///
7/// For customized encoding please see [`Encode`] trait for detail.
8/// For customized decoding please see [`IntoResponse`] trait for detail.
9///
10/// when to use `execute` or `query` methods:
11/// - `execute` method is for use case where sql produce an outcome where it only happen once.
12///     usually in the form of preparing a statement or observing how many rows have been modified.
13/// - `query` method is for use case where sql produce repeated outcome where it can happen multiple times.
14///     usually in the form of visiting an iteration of database rows.
15///
16/// [`Encode`]: crate::driver::codec::encode::Encode
17/// [`IntoResponse`]: crate::driver::codec::response::IntoResponse
18pub trait Execute<'c, C>
19where
20    Self: Sized,
21{
22    /// outcome of execute.
23    /// used for single time database response: number of rows affected by execution for example.
24    type ExecuteOutput;
25
26    /// outcome of query.
27    /// used for repeated database response: database rows for example
28    ///
29    /// consider impl [`AsyncLendingIterator`] for async iterator of rows
30    /// consider impl [`Iterator`] for iterator of rows
31    ///
32    /// for type of statement where no repeated response will returning this type can point to
33    /// [`Execute::ExecuteOutput`] and it's encouraged to make `query` behave identical to `execute`
34    ///
35    /// [`AsyncLendingIterator`]: crate::iter::AsyncLendingIterator
36    type QueryOutput;
37
38    /// define how a statement is executed with single time response
39    fn execute(self, cli: &'c C) -> Self::ExecuteOutput;
40
41    /// define how a statement is queried with repeated response
42    fn query(self, cli: &'c C) -> Self::QueryOutput;
43}
44
45/// mutable version of [`Execute`] trait where C type is mutably borrowed
46pub trait ExecuteMut<'c, C>
47where
48    Self: Sized,
49{
50    type ExecuteMutOutput;
51    type QueryMutOutput;
52
53    fn execute_mut(self, cli: &'c mut C) -> Self::ExecuteMutOutput;
54
55    fn query_mut(self, cli: &'c mut C) -> Self::QueryMutOutput;
56}
57
58/// blocking version of [`Execute`] for synchronous environment
59pub trait ExecuteBlocking<'c, C>
60where
61    Self: Sized,
62{
63    type ExecuteOutput;
64    type QueryOutput;
65
66    fn execute_blocking(self, cli: &'c C) -> Self::ExecuteOutput;
67
68    fn query_blocking(self, cli: &'c C) -> Self::QueryOutput;
69}