Wrap logic of the insert! macro in a transaction
This commit is contained in:
parent
8709f6cf9f
commit
f86d3a68f4
@ -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 )+
|
||||||
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user