1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::connection::ConnectOptions;
use crate::error::Error;
use crate::executor::Executor;
use crate::mysql::{MySqlConnectOptions, MySqlConnection};
use futures_core::future::BoxFuture;
use log::LevelFilter;
use std::time::Duration;
impl ConnectOptions for MySqlConnectOptions {
type Connection = MySqlConnection;
fn connect(&self) -> BoxFuture<'_, Result<Self::Connection, Error>>
where
Self::Connection: Sized,
{
Box::pin(async move {
let mut conn = MySqlConnection::establish(self).await?;
let mut options = String::new();
if self.pipes_as_concat {
options.push_str(r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),"#);
} else {
options.push_str(
r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',NO_ENGINE_SUBSTITUTION')),"#,
);
}
options.push_str(r#"time_zone='+00:00',"#);
options.push_str(&format!(
r#"NAMES {} COLLATE {};"#,
conn.stream.charset.as_str(),
conn.stream.collation.as_str()
));
conn.execute(&*options).await?;
Ok(conn)
})
}
fn log_statements(&mut self, level: LevelFilter) -> &mut Self {
self.log_settings.log_statements(level);
self
}
fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self {
self.log_settings.log_slow_statements(level, duration);
self
}
}