Skip to content

Commit

Permalink
Implement default DataObject.delete() (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Jan 14, 2024
1 parent ac7ebdd commit cbe4c9d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 0 additions & 5 deletions butane_core/src/codegen/dbobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ pub fn impl_dbobject(ast_struct: &ItemStruct, config: &Config) -> TokenStream2 {
#many_save
Ok(())
}
fn delete(&self, conn: &impl butane::db::ConnectionMethods) -> butane::Result<()> {
use butane::ToSql;
use butane::prelude::DataObject;
conn.delete(Self::TABLE, Self::PKCOL, self.pk().to_sql())
}
}
impl butane::ToSql for #tyname {
fn to_sql(&self) -> butane::SqlVal {
Expand Down
4 changes: 3 additions & 1 deletion butane_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ pub trait DataObject: DataResult<DBO = Self> {
/// Save the object to the database.
fn save(&mut self, conn: &impl ConnectionMethods) -> Result<()>;
/// Delete the object from the database.
fn delete(&self, conn: &impl ConnectionMethods) -> Result<()>;
fn delete(&self, conn: &impl ConnectionMethods) -> Result<()> {
conn.delete(Self::TABLE, Self::PKCOL, self.pk().to_sql())
}
}

pub trait ModelTyped {
Expand Down

0 comments on commit cbe4c9d

Please sign in to comment.