@@ -45,6 +45,14 @@ impl<'conn, 'query> AsyncConnectionGatWorkaround<'conn, 'query, Mysql> for Async
45
45
type Row = MysqlRow ;
46
46
}
47
47
48
+ const CONNECTION_SETUP_QUERIES : & ' static [ & ' static str ] = & [
49
+ "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT'))" ,
50
+ "SET time_zone = '+00:00';" ,
51
+ "SET character_set_client = 'utf8mb4'" ,
52
+ "SET character_set_connection = 'utf8mb4'" ,
53
+ "SET character_set_results = 'utf8mb4'" ,
54
+ ] ;
55
+
48
56
#[ async_trait:: async_trait]
49
57
impl AsyncConnection for AsyncMysqlConnection {
50
58
type Backend = Mysql ;
@@ -55,13 +63,7 @@ impl AsyncConnection for AsyncMysqlConnection {
55
63
let opts = Opts :: from_url ( database_url)
56
64
. map_err ( |e| diesel:: result:: ConnectionError :: InvalidConnectionUrl ( e. to_string ( ) ) ) ?;
57
65
let builder = OptsBuilder :: from_opts ( opts)
58
- . init ( vec ! [
59
- "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT'))" ,
60
- "SET time_zone = '+00:00';" ,
61
- "SET character_set_client = 'utf8mb4'" ,
62
- "SET character_set_connection = 'utf8mb4'" ,
63
- "SET character_set_results = 'utf8mb4'" ,
64
- ] )
66
+ . init ( CONNECTION_SETUP_QUERIES . to_vec ( ) )
65
67
. stmt_cache_size ( 0 ) ; // We have our own cache
66
68
67
69
let conn = mysql_async:: Conn :: new ( builder) . await . map_err ( ErrorHelper ) ?;
@@ -86,7 +88,7 @@ impl AsyncConnection for AsyncMysqlConnection {
86
88
+ ' query ,
87
89
{
88
90
self . with_prepared_statement ( source. as_query ( ) , |conn, stmt, binds| async move {
89
- let res = conn. exec_iter ( & * stmt, binds) . await . map_err ( ErrorHelper ) ?;
91
+ let res = conn. exec_iter ( stmt, binds) . await . map_err ( ErrorHelper ) ?;
90
92
91
93
let stream = res
92
94
. stream_and_drop :: < MysqlRow > ( )
@@ -116,7 +118,7 @@ impl AsyncConnection for AsyncMysqlConnection {
116
118
+ ' query ,
117
119
{
118
120
self . with_prepared_statement ( source, |conn, stmt, binds| async move {
119
- conn. exec_drop ( & * stmt, binds) . await . map_err ( ErrorHelper ) ?;
121
+ conn. exec_drop ( stmt, binds) . await . map_err ( ErrorHelper ) ?;
120
122
Ok ( conn. affected_rows ( ) as usize )
121
123
} )
122
124
}
@@ -169,16 +171,9 @@ impl AsyncMysqlConnection {
169
171
transaction_manager : AnsiTransactionManager :: default ( ) ,
170
172
last_stmt : None ,
171
173
} ;
172
- let setup_statements = vec ! [
173
- "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT'))" ,
174
- "SET time_zone = '+00:00';" ,
175
- "SET character_set_client = 'utf8mb4'" ,
176
- "SET character_set_connection = 'utf8mb4'" ,
177
- "SET character_set_results = 'utf8mb4'" ,
178
- ] ;
179
-
180
- for stmt in setup_statements {
181
- diesel:: sql_query ( stmt)
174
+
175
+ for stmt in CONNECTION_SETUP_QUERIES {
176
+ diesel:: sql_query ( * stmt)
182
177
. execute ( & mut conn)
183
178
. await
184
179
. map_err ( ConnectionError :: CouldntSetupConfiguration ) ?;
0 commit comments