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,6 +261,8 @@ 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> {
use diesel::connection::Connection as _;
conn.transaction::<_, Error, _>(|| {
diesel::insert_into($table::table) diesel::insert_into($table::table)
.values(new) .values(new)
.execute(conn)?; .execute(conn)?;
@ -268,6 +270,7 @@ macro_rules! insert {
let mut $val = Self::last(conn)?; let mut $val = Self::last(conn)?;
let $conn = conn; let $conn = conn;
$( $after )+ $( $after )+
})
} }
}; };
} }