home
·
contact
·
privacy
projects
/
plomtask
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Minor stylistic improvements to tests code.
[plomtask]
/
plomtask
/
db.py
diff --git
a/plomtask/db.py
b/plomtask/db.py
index ebd8c6c544fd9dd3aca7e040bccb3d354629806d..deeb748de0b427b1ff2f999e58713d3cee4e7807 100644
(file)
--- a/
plomtask/db.py
+++ b/
plomtask/db.py
@@
-102,7
+102,8
@@
class DatabaseConnection:
return [row[0] for row in
self.exec(f'SELECT {column} FROM {table_name}')]
return [row[0] for row in
self.exec(f'SELECT {column} FROM {table_name}')]
- def delete_where(self, table_name: str, key: str, target: int) -> None:
+ def delete_where(self, table_name: str, key: str,
+ target: int | str) -> None:
"""Delete from table where key == target."""
self.exec(f'DELETE FROM {table_name} WHERE {key} = ?', (target,))
"""Delete from table where key == target."""
self.exec(f'DELETE FROM {table_name} WHERE {key} = ?', (target,))
@@
-234,3
+235,9
@@
class BaseModel(Generic[BaseModelId]):
if update_with_lastrowid:
self.id_ = cursor.lastrowid # type: ignore[assignment]
self.cache()
if update_with_lastrowid:
self.id_ = cursor.lastrowid # type: ignore[assignment]
self.cache()
+
+ def remove(self, db_conn: DatabaseConnection) -> None:
+ """Remove from DB."""
+ assert isinstance(self.id_, int | str)
+ self.uncache()
+ db_conn.delete_where(self.table_name, 'id', self.id_)