name delete if 0 attributions

This commit is contained in:
2026-04-09 19:29:12 +02:00
parent ab01d0d275
commit 3f98a10df8
4 changed files with 61 additions and 3 deletions

View File

@@ -171,6 +171,16 @@ impl Name {
})?
.collect::<Result<Vec<Name>, _>>()?)
}
pub fn times_attributed(&self, conn: &Connection) -> Result<i64, PersonError> {
Ok(conn
.prepare("SELECT COUNT(*) FROM lines WHERE name_id = ?1")?
.query_row((&self.id,), |r| r.get(0))?)
}
pub fn delete(self, conn: &Connection) -> Result<(), PersonError> {
conn.prepare("DELETE FROM names WHERE id = ?1")?
.execute((&self.id,))?;
Ok(())
}
pub fn set_primary(&mut self, conn: &Connection) -> Result<(), PersonError> {
if self.is_primary {
return Err(PersonError::AlreadyPrimary);