Sqlite allows deleting the datapoints automatically on deletion of the habit. There's multiple ways to do that. My first impression is that ON DELETE CASCADE is the most straightforward way to do it.
Also, the first SELECT is unnecessary. You can just DELETE entries directly (if they don't exist, you won't delete anything).
Using the two suggestions above, you can implement habit deletion with a single DELETE FROM habits WHERE habit = ? and login = ? query. This simplifies the code, and also uses Sqlite in a more canonical way.
https://github.com/thermobased/flask-webapp/blob/bc938fa015090d7f46bfcf661d026edc26875b90/main.py#L165-L168
Sqlite allows deleting the datapoints automatically on deletion of the habit. There's multiple ways to do that. My first impression is that
ON DELETE CASCADE
is the most straightforward way to do it.Also, the first
SELECT
is unnecessary. You can justDELETE
entries directly (if they don't exist, you won't delete anything).Using the two suggestions above, you can implement habit deletion with a single
DELETE FROM habits WHERE habit = ? and login = ?
query. This simplifies the code, and also uses Sqlite in a more canonical way.Ivan