|
@@ -464,6 +464,40 @@ pub trait Queryable: Clone {
|
|
|
txn.commit()
|
|
|
}
|
|
|
|
|
|
+ /// Delete all entities in the current context and return them
|
|
|
+ fn remove(self) -> DBResult<Self::OutputContainer>
|
|
|
+ where
|
|
|
+ Self: Sized,
|
|
|
+ {
|
|
|
+ let txn = Transaction::new(self.conn())?;
|
|
|
+ struct DeleteTag;
|
|
|
+ let out = self.conn().with_prepared(
|
|
|
+ std::any::TypeId::of::<(Self::StaticVersion, DeleteTag)>(),
|
|
|
+ || {
|
|
|
+ format!(
|
|
|
+ "DELETE FROM `{entity}` WHERE `id` = ({subquery}) RETURNING *",
|
|
|
+ entity = Self::EntityOutput::entity_name(),
|
|
|
+ subquery = self
|
|
|
+ .build()
|
|
|
+ .replace(
|
|
|
+ QueryPart::Columns,
|
|
|
+ format!("`{}`.`id`", Self::EntityOutput::entity_name())
|
|
|
+ )
|
|
|
+ .assemble()
|
|
|
+ )
|
|
|
+ },
|
|
|
+ |mut ctx| {
|
|
|
+ // starting index is 1
|
|
|
+ let mut index = 1;
|
|
|
+ self.bind(&mut ctx, &mut index);
|
|
|
+
|
|
|
+ <Self::OutputContainer>::assemble_from(self.conn(), ctx)
|
|
|
+ },
|
|
|
+ )?;
|
|
|
+ txn.commit()?;
|
|
|
+ Ok(out)
|
|
|
+ }
|
|
|
+
|
|
|
// ----------------------------------------------------------------------
|
|
|
// Filtering methods
|
|
|
// ----------------------------------------------------------------------
|