sqlx_core/any/connection/
backend.rs1use crate::any::{Any, AnyArguments, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo};
2use crate::describe::Describe;
3use either::Either;
4use futures_core::future::BoxFuture;
5use futures_core::stream::BoxStream;
6use std::borrow::Cow;
7use std::fmt::Debug;
8
9pub trait AnyConnectionBackend: std::any::Any + Debug + Send + 'static {
10 fn name(&self) -> &str;
12
13 fn close(self: Box<Self>) -> BoxFuture<'static, crate::Result<()>>;
19
20 #[doc(hidden)]
24 fn close_hard(self: Box<Self>) -> BoxFuture<'static, crate::Result<()>>;
25
26 fn ping(&mut self) -> BoxFuture<'_, crate::Result<()>>;
28
29 fn begin(&mut self, statement: Option<Cow<'static, str>>) -> BoxFuture<'_, crate::Result<()>>;
37
38 fn commit(&mut self) -> BoxFuture<'_, crate::Result<()>>;
39
40 fn rollback(&mut self) -> BoxFuture<'_, crate::Result<()>>;
41
42 fn start_rollback(&mut self);
43
44 fn get_transaction_depth(&self) -> usize {
51 unimplemented!("get_transaction_depth() is not implemented for this backend. This is a provided method to avoid a breaking change, but it will become a required method in version 0.9 and later.");
52 }
53
54 #[inline]
60 fn is_in_transaction(&self) -> bool {
61 self.get_transaction_depth() != 0
62 }
63
64 fn cached_statements_size(&self) -> usize {
66 0
67 }
68
69 fn clear_cached_statements(&mut self) -> BoxFuture<'_, crate::Result<()>> {
72 Box::pin(async move { Ok(()) })
73 }
74
75 fn shrink_buffers(&mut self);
79
80 #[doc(hidden)]
81 fn flush(&mut self) -> BoxFuture<'_, crate::Result<()>>;
82
83 #[doc(hidden)]
84 fn should_flush(&self) -> bool;
85
86 #[cfg(feature = "migrate")]
87 fn as_migrate(&mut self) -> crate::Result<&mut (dyn crate::migrate::Migrate + Send + 'static)> {
88 Err(crate::Error::Configuration(
89 format!(
90 "{} driver does not support migrations or `migrate` feature was not enabled",
91 self.name()
92 )
93 .into(),
94 ))
95 }
96
97 fn fetch_many<'q>(
98 &'q mut self,
99 query: &'q str,
100 persistent: bool,
101 arguments: Option<AnyArguments<'q>>,
102 ) -> BoxStream<'q, crate::Result<Either<AnyQueryResult, AnyRow>>>;
103
104 fn fetch_optional<'q>(
105 &'q mut self,
106 query: &'q str,
107 persistent: bool,
108 arguments: Option<AnyArguments<'q>>,
109 ) -> BoxFuture<'q, crate::Result<Option<AnyRow>>>;
110
111 fn prepare_with<'c, 'q: 'c>(
112 &'c mut self,
113 sql: &'q str,
114 parameters: &[AnyTypeInfo],
115 ) -> BoxFuture<'c, crate::Result<AnyStatement<'q>>>;
116
117 fn describe<'q>(&'q mut self, sql: &'q str) -> BoxFuture<'q, crate::Result<Describe<Any>>>;
118}