Wrap logic of the insert! macro in a transaction

This commit is contained in:
Quentin Dufour 2022-04-25 13:37:08 +02:00
parent 8709f6cf9f
commit f86d3a68f4
No known key found for this signature in database
GPG Key ID: E9602264D639FF68

View File

@ -261,13 +261,16 @@ macro_rules! insert {
#[allow(dead_code)] #[allow(dead_code)]
pub fn insert(conn: &crate::Connection, new: $from) -> Result<Self> { pub fn insert(conn: &crate::Connection, new: $from) -> Result<Self> {
diesel::insert_into($table::table) use diesel::connection::Connection as _;
.values(new) conn.transaction::<_, Error, _>(|| {
.execute(conn)?; diesel::insert_into($table::table)
#[allow(unused_mut)] .values(new)
let mut $val = Self::last(conn)?; .execute(conn)?;
let $conn = conn; #[allow(unused_mut)]
$( $after )+ let mut $val = Self::last(conn)?;
let $conn = conn;
$( $after )+
})
} }
}; };
} }