Skip to content

Commit

Permalink
diesel/src/mysql/connection/mod.rs: impl ConnectionWithReturningId fo…
Browse files Browse the repository at this point in the history
…r MysqlConnection
  • Loading branch information
mcronce committed Sep 19, 2024
1 parent b94887f commit 6a2277e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions diesel/src/mysql/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,34 @@ impl Connection for MysqlConnection {
}
}

impl ConnectionWithReturningId for MysqlConnection {
type ReturnedId = u64;

fn execute_returning_id<T>(&mut self, source: &T) -> QueryResult<Self::ReturnedId>
where
T: QueryFragment<Self::Backend> + QueryId,
{
#[allow(unsafe_code)] // call to unsafe function
update_transaction_manager_status(
prepared_query(
&source,
&mut self.statement_cache,
&mut self.raw_connection,
&mut *self.instrumentation,
)
.and_then(|stmt| {
// we have not called result yet, so calling `execute` is
// fine
let stmt_use = unsafe { stmt.execute() }?;
Ok(unsafe { stmt_use.insert_id() })
}),
&mut self.transaction_state,
&mut self.instrumentation,
&crate::debug_query(source),
)
}
}

#[inline(always)]
fn update_transaction_manager_status<T>(
query_result: QueryResult<T>,
Expand Down

0 comments on commit 6a2277e

Please sign in to comment.