Debian Codegraph @

src/options/connect.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::connectionrust-analyzer cargo sqlx-mysql 0.8.3 connection/::ConnectOptionsrust-analyzer cargo sqlx-core 0.8.3 connection/ConnectOptions#;
2 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::errorrust-analyzer cargo sqlx-mysql 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
3 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::executorrust-analyzer cargo sqlx-core 0.8.3 executor/::Executorrust-analyzer cargo sqlx-core 0.8.3 executor/Executor#;
4 use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::{MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#, MySqlConnectionrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnection#};
5 use futures_corerust-analyzer cargo futures-core 0.3.34 crate/::futurerust-analyzer cargo futures-core 0.3.34 future/::BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#;
6 use logrust-analyzer cargo log 0.4.34 crate/::LevelFilterrust-analyzer cargo log 0.4.34 LevelFilter#;
7 use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::Urlrust-analyzer cargo url 2.5.8 Url#;
8 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#;
9
10 impl ConnectOptionsrust-analyzer cargo sqlx-core 0.8.3 connection/ConnectOptions# for MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions# {
11 type Connectionrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]Connection# = MySqlConnectionrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnection#;
12
13 fn from_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]from_url().(url: &Urlrust-analyzer cargo url 2.5.8 Url#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
14 Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]::parse_from_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]parse_from_url().(url)
15 }
16
17 fn to_url_lossyrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]to_url_lossy().(&self) -> Urlrust-analyzer cargo url 2.5.8 Url# {
18 self.build_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]build_url().()
19 }
20
21 fn connectrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]connect().(&self) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]::Connectionrust-analyzer cargo sqlx-core 0.8.3 connection/ConnectOptions#Connection#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>>
22 where
23 Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]::Connectionrust-analyzer cargo sqlx-core 0.8.3 connection/ConnectOptions#Connection#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
24 {
25 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move {
26 let mut conn = MySqlConnectionrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnection#::establishrust-analyzer cargo sqlx-mysql 0.8.3 connection/establish/impl#[MySqlConnection]establish().(self).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
27
28 // After the connection is established, we initialize by configuring a few
29 // connection parameters
30
31 // https://mariadb.com/kb/en/sql-mode/
32
33 // PIPES_AS_CONCAT - Allows using the pipe character (ASCII 124) as string concatenation operator.
34 // This means that "A" || "B" can be used in place of CONCAT("A", "B").
35
36 // NO_ENGINE_SUBSTITUTION - If not set, if the available storage engine specified by a CREATE TABLE is
37 // not available, a warning is given and the default storage
38 // engine is used instead.
39
40 // NO_ZERO_DATE - Don't allow '0000-00-00'. This is invalid in Rust.
41
42 // NO_ZERO_IN_DATE - Don't allow 'YYYY-00-00'. This is invalid in Rust.
43
44 // --
45
46 // Setting the time zone allows us to assume that the output
47 // from a TIMESTAMP field is UTC
48
49 // --
50
51 // https://mathiasbynens.be/notes/mysql-utf8mb4
52
53 let mut sql_mode = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
54 if self.pipes_as_concatrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#pipes_as_concat. {
55 sql_mode.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(r#"PIPES_AS_CONCAT"#);
56 }
57 if self.no_engine_substitutionrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#no_engine_substitution. {
58 sql_mode.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(r#"NO_ENGINE_SUBSTITUTION"#);
59 }
60
61 let mut options = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
62 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sql_mode.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
63 options.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
64 r#"sql_mode=(SELECT CONCAT(@@sql_mode, ',{}'))"#,
65 sql_mode.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(",")
66 ));
67 }
68 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(timezone) = &self.timezonerust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#timezone. {
69 options.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(r#"time_zone='{}'"#, timezone));
70 }
71 if self.set_namesrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#set_names. {
72 options.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
73 r#"NAMES {} COLLATE {}"#,
74 conn.innerrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnection#inner..streamrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnectionInner#stream..charsetrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#charset..as_strrust-analyzer cargo sqlx-mysql 0.8.3 collation/impl#[CharSet]as_str().(),
75 conn.innerrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnection#inner..streamrust-analyzer cargo sqlx-mysql 0.8.3 connection/MySqlConnectionInner#stream..collationrust-analyzer cargo sqlx-mysql 0.8.3 connection/stream/MySqlStream#collation..as_strrust-analyzer cargo sqlx-mysql 0.8.3 collation/impl#[Collation]as_str().()
76 ))
77 }
78
79 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().options.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
80 conn.executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(r#"SET {};"#, options.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(",")))
81 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
82 }
83
84 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(conn)
85 })
86 }
87
88 fn log_statementsrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]log_statements().(mut self, level: LevelFilterrust-analyzer cargo log 0.4.34 LevelFilter#) -> Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions] {
89 self.log_settingsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#log_settings..log_statementsrust-analyzer cargo sqlx-core 0.8.3 connection/impl#[LogSettings]log_statements().(level);
90 self
91 }
92
93 fn log_slow_statementsrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions]log_slow_statements().(mut self, level: LevelFilterrust-analyzer cargo log 0.4.34 LevelFilter#, duration: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) -> Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/connect/impl#[MySqlConnectOptions][ConnectOptions] {
94 self.log_settingsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#log_settings..log_slow_statementsrust-analyzer cargo sqlx-core 0.8.3 connection/impl#[LogSettings]log_slow_statements().(level, duration);
95 self
96 }
97 }