Skip to content

Commit c6639ec

Browse files
committed
diesel/src/mysql/connection/mod.rs: impl ConnectionWithReturningId for MysqlConnection
1 parent edb451d commit c6639ec

File tree

1 file changed

+28
-0
lines changed
  • diesel/src/mysql/connection

1 file changed

+28
-0
lines changed

diesel/src/mysql/connection/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,34 @@ impl Connection for MysqlConnection {
211211
}
212212
}
213213

214+
impl ConnectionWithReturningId for MysqlConnection {
215+
type ReturnedId = u64;
216+
217+
fn execute_returning_id<T>(&mut self, source: &T) -> QueryResult<Self::ReturnedId>
218+
where
219+
T: QueryFragment<Self::Backend> + QueryId,
220+
{
221+
#[allow(unsafe_code)] // call to unsafe function
222+
update_transaction_manager_status(
223+
prepared_query(
224+
&source,
225+
&mut self.statement_cache,
226+
&mut self.raw_connection,
227+
&mut *self.instrumentation,
228+
)
229+
.and_then(|stmt| {
230+
// we have not called result yet, so calling `execute` is
231+
// fine
232+
let stmt_use = unsafe { stmt.execute() }?;
233+
Ok(unsafe { stmt_use.insert_id() })
234+
}),
235+
&mut self.transaction_state,
236+
&mut self.instrumentation,
237+
&crate::debug_query(source),
238+
)
239+
}
240+
}
241+
214242
#[inline(always)]
215243
fn update_transaction_manager_status<T>(
216244
query_result: QueryResult<T>,

0 commit comments

Comments
 (0)