1
+ use crate :: statement_cache:: CacheSize ;
2
+ use crate :: statement_cache:: { MaybeCached , QueryFragmentForCachedStatement , StatementCache } ;
1
3
use crate :: stmt_cache:: { CallbackHelper , QueryFragmentHelper } ;
2
4
use crate :: { AnsiTransactionManager , AsyncConnection , SimpleAsyncConnection } ;
3
- use diesel:: connection:: statement_cache:: {
4
- MaybeCached , QueryFragmentForCachedStatement , StatementCache ,
5
- } ;
5
+ use diesel:: connection:: Instrumentation ;
6
+ use diesel:: connection:: InstrumentationEvent ;
6
7
use diesel:: connection:: StrQueryHelper ;
7
- use diesel:: connection:: { CacheSize , Instrumentation } ;
8
- use diesel:: connection:: { DynInstrumentation , InstrumentationEvent } ;
9
8
use diesel:: mysql:: { Mysql , MysqlQueryBuilder , MysqlType } ;
10
9
use diesel:: query_builder:: QueryBuilder ;
11
10
use diesel:: query_builder:: { bind_collector:: RawBytesBindCollector , QueryFragment , QueryId } ;
@@ -33,7 +32,7 @@ pub struct AsyncMysqlConnection {
33
32
conn : mysql_async:: Conn ,
34
33
stmt_cache : StatementCache < Mysql , Statement > ,
35
34
transaction_manager : AnsiTransactionManager ,
36
- instrumentation : DynInstrumentation ,
35
+ instrumentation : Option < Box < dyn Instrumentation > > ,
37
36
}
38
37
39
38
impl SimpleAsyncConnection for AsyncMysqlConnection {
@@ -74,7 +73,7 @@ impl AsyncConnection for AsyncMysqlConnection {
74
73
type TransactionManager = AnsiTransactionManager ;
75
74
76
75
async fn establish ( database_url : & str ) -> diesel:: ConnectionResult < Self > {
77
- let mut instrumentation = DynInstrumentation :: default_instrumentation ( ) ;
76
+ let mut instrumentation = diesel :: connection :: get_default_instrumentation ( ) ;
78
77
instrumentation. on_connection_event ( InstrumentationEvent :: start_establish_connection (
79
78
database_url,
80
79
) ) ;
@@ -99,10 +98,6 @@ impl AsyncConnection for AsyncMysqlConnection {
99
98
let stmt_for_exec = match stmt {
100
99
MaybeCached :: Cached ( ref s) => ( * s) . clone ( ) ,
101
100
MaybeCached :: CannotCache ( ref s) => s. clone ( ) ,
102
- _ => unreachable ! (
103
- "Diesel has only two variants here at the time of writing.\n \
104
- If you ever see this error message please open in issue in the diesel-async issue tracker"
105
- ) ,
106
101
} ;
107
102
108
103
let ( tx, rx) = futures_channel:: mpsc:: channel ( 0 ) ;
@@ -179,11 +174,11 @@ impl AsyncConnection for AsyncMysqlConnection {
179
174
}
180
175
181
176
fn instrumentation ( & mut self ) -> & mut dyn Instrumentation {
182
- & mut * self . instrumentation
177
+ & mut self . instrumentation
183
178
}
184
179
185
180
fn set_instrumentation ( & mut self , instrumentation : impl Instrumentation ) {
186
- self . instrumentation = instrumentation . into ( ) ;
181
+ self . instrumentation = Some ( Box :: new ( instrumentation ) ) ;
187
182
}
188
183
189
184
fn set_prepared_statement_cache_size ( & mut self , size : CacheSize ) {
@@ -211,7 +206,7 @@ fn update_transaction_manager_status<T>(
211
206
fn prepare_statement_helper < ' a > (
212
207
conn : & ' a mut mysql_async:: Conn ,
213
208
sql : & str ,
214
- _is_for_cache : diesel :: connection :: statement_cache:: PrepareForCache ,
209
+ _is_for_cache : crate :: statement_cache:: PrepareForCache ,
215
210
_metadata : & [ MysqlType ] ,
216
211
) -> CallbackHelper < impl Future < Output = QueryResult < ( Statement , & ' a mut mysql_async:: Conn ) > > + Send >
217
212
{
@@ -239,7 +234,7 @@ impl AsyncMysqlConnection {
239
234
conn,
240
235
stmt_cache : StatementCache :: new ( ) ,
241
236
transaction_manager : AnsiTransactionManager :: default ( ) ,
242
- instrumentation : DynInstrumentation :: default_instrumentation ( ) ,
237
+ instrumentation : diesel :: connection :: get_default_instrumentation ( ) ,
243
238
} ;
244
239
245
240
for stmt in CONNECTION_SETUP_QUERIES {
@@ -296,21 +291,25 @@ impl AsyncMysqlConnection {
296
291
sql,
297
292
safe_to_cache : is_safe_to_cache_prepared,
298
293
} ;
294
+
299
295
let inner = async {
300
- let ( stmt, conn) = stmt_cache
301
- . cached_statement_non_generic (
302
- query_id,
303
- & helper,
304
- & Mysql ,
305
- & metadata,
306
- conn,
307
- prepare_statement_helper,
308
- & mut * * instrumentation,
309
- )
310
- . await ?;
296
+ let ( stmt, conn) = {
297
+ stmt_cache
298
+ . cached_statement_non_generic (
299
+ query_id,
300
+ & helper,
301
+ & Mysql ,
302
+ & metadata,
303
+ conn,
304
+ prepare_statement_helper,
305
+ & mut * instrumentation,
306
+ )
307
+ . await ?
308
+ } ;
311
309
callback ( conn, stmt, ToSqlHelper { metadata, binds } ) . await
312
310
} ;
313
311
let r = update_transaction_manager_status ( inner. await , transaction_manager) ;
312
+
314
313
instrumentation. on_connection_event ( InstrumentationEvent :: finish_query (
315
314
& StrQueryHelper :: new ( & helper. sql ) ,
316
315
r. as_ref ( ) . err ( ) ,
@@ -371,7 +370,7 @@ impl AsyncMysqlConnection {
371
370
conn,
372
371
stmt_cache : StatementCache :: new ( ) ,
373
372
transaction_manager : AnsiTransactionManager :: default ( ) ,
374
- instrumentation : DynInstrumentation :: none ( ) ,
373
+ instrumentation : diesel :: connection :: get_default_instrumentation ( ) ,
375
374
} )
376
375
}
377
376
}
0 commit comments