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::fmt::Debug;
7
8pub trait AnyConnectionBackend: std::any::Any + Debug + Send + 'static {
9 fn name(&self) -> &str;
11
12 fn close(self: Box<Self>) -> BoxFuture<'static, crate::Result<()>>;
18
19 #[doc(hidden)]
23 fn close_hard(self: Box<Self>) -> BoxFuture<'static, crate::Result<()>>;
24
25 fn ping(&mut self) -> BoxFuture<'_, crate::Result<()>>;
27
28 fn begin(&mut self) -> BoxFuture<'_, crate::Result<()>>;
32
33 fn commit(&mut self) -> BoxFuture<'_, crate::Result<()>>;
34
35 fn rollback(&mut self) -> BoxFuture<'_, crate::Result<()>>;
36
37 fn start_rollback(&mut self);
38
39 fn cached_statements_size(&self) -> usize {
41 0
42 }
43
44 fn clear_cached_statements(&mut self) -> BoxFuture<'_, crate::Result<()>> {
47 Box::pin(async move { Ok(()) })
48 }
49
50 fn shrink_buffers(&mut self);
54
55 #[doc(hidden)]
56 fn flush(&mut self) -> BoxFuture<'_, crate::Result<()>>;
57
58 #[doc(hidden)]
59 fn should_flush(&self) -> bool;
60
61 #[cfg(feature = "migrate")]
62 fn as_migrate(&mut self) -> crate::Result<&mut (dyn crate::migrate::Migrate + Send + 'static)> {
63 Err(crate::Error::Configuration(
64 format!(
65 "{} driver does not support migrations or `migrate` feature was not enabled",
66 self.name()
67 )
68 .into(),
69 ))
70 }
71
72 fn fetch_many<'q>(
73 &'q mut self,
74 query: &'q str,
75 arguments: Option<AnyArguments<'q>>,
76 ) -> BoxStream<'q, crate::Result<Either<AnyQueryResult, AnyRow>>>;
77
78 fn fetch_optional<'q>(
79 &'q mut self,
80 query: &'q str,
81 arguments: Option<AnyArguments<'q>>,
82 ) -> BoxFuture<'q, crate::Result<Option<AnyRow>>>;
83
84 fn prepare_with<'c, 'q: 'c>(
85 &'c mut self,
86 sql: &'q str,
87 parameters: &[AnyTypeInfo],
88 ) -> BoxFuture<'c, crate::Result<AnyStatement<'q>>>;
89
90 fn describe<'q>(&'q mut self, sql: &'q str) -> BoxFuture<'q, crate::Result<Describe<Any>>>;
91}