Skip to main content

diesel_async/mysql/
mod.rs

1use std::borrow::Cow;
2
3use diesel::connection::statement_cache::QueryFragmentForCachedStatement;
4use diesel::mysql::Mysql;
5use diesel::prelude::QueryResult;
6
7use crate::mysql_like::UrlHelper;
8use crate::stmt_cache::QueryFragmentHelper;
9
10use super::mysql_like::AsyncMysqlLikeConnection;
11use super::mysql_like::MysqlLikeCancelToken;
12
13/// The capability to request cancellation of in-progress queries on a
14/// connection.
15pub type MysqlCancelToken = MysqlLikeCancelToken<Mysql>;
16
17/// A connection to a MySQL database. Connection URLs should be in the form
18/// `mysql://[user[:password]@]host/database_name`
19///
20/// # Cancellation and timeouts
21///
22/// Dropping a query future before it completes, for example when a timeout
23/// expires, can leave this connection with an unfinished operation. Such a
24/// connection must not be reused: drop it and establish a new connection
25/// instead. Cancelling the future does not guarantee that the server stopped
26/// executing the query or rolled back its effects.
27///
28/// The connection pool integrations detect this state and discard the broken
29/// connection when it is returned to the pool. Users managing connections
30/// without a pool must handle this themselves whenever they cancel or time out
31/// an operation.
32pub type AsyncMysqlConnection = AsyncMysqlLikeConnection<Mysql>;
33
34impl QueryFragmentForCachedStatement<Mysql> for QueryFragmentHelper {
35    fn construct_sql(&self, _backend: &Mysql) -> QueryResult<String> {
36        Ok(self.sql.clone())
37    }
38
39    fn is_safe_to_cache_prepared(&self, _backend: &Mysql) -> QueryResult<bool> {
40        Ok(self.safe_to_cache)
41    }
42
43    fn parameter_count(&self, _backend: &Mysql) -> QueryResult<usize> {
44        Ok(self.bind_count)
45    }
46}
47
48impl UrlHelper for Mysql {
49    //`mysql_async` checks this for us
50    fn check_and_replace_schema<'a>(url: &'a str) -> Result<Cow<'a, str>, mysql_async::UrlError> {
51        Ok(url.into())
52    }
53}