From b4ed8070d5f5d8b537e1d8a4a9b71707b4badbe9 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sun, 22 May 2022 22:41:37 +0000 Subject: [PATCH] add delete_feed method --- database_interaction.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/database_interaction.py b/database_interaction.py index 17c1d42..0003754 100644 --- a/database_interaction.py +++ b/database_interaction.py @@ -13,18 +13,21 @@ class Database(): self.conn.commit() return self.cur.lastrowid - def get_user(self, telegram_id: str) -> tuple | None: + def get_user(self, telegram_id: str) -> int | None: self.cur.execute('SELECT id FROM users WHERE telegram_id = :telegram_id', {'telegram_id': telegram_id}) user_id = self.cur.fetchone() - return user_id + if user_id is None: + return None + return user_id[0] def add_feed(self, link: str) -> int: self.cur.execute('INSERT INTO feeds (link) VALUES (:link)', {'link': link}) self.conn.commit() return self.cur.lastrowid - def delete_feed(): - pass + def delete_feed(self, feed_id: int) -> None: + self.cur.execute('DELETE FROM feeds WHERE id = :feed_id', {'feed_id': feed_id}) + self.conn.commit() def get_feeds(): pass