From 5d0a6843b67aa96ee904a18393aa64402f9b755f Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Wed, 13 Jul 2022 20:15:11 +0000 Subject: [PATCH] fix return values in add_user and add_feed methods --- database.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/database.py b/database.py index 9a20480..6d8c947 100644 --- a/database.py +++ b/database.py @@ -22,9 +22,9 @@ class Database: def add_user(self, telegram_id: int) -> int: """Add a user's telegram id to the database and return its database id.""" self.log.debug('add_user(telegram_id=\'%s\')', telegram_id) - id = self.cur.execute('INSERT INTO users (telegram_id) VALUES (%s) RETURNING id', [telegram_id]) + self.cur.execute('INSERT INTO users (telegram_id) VALUES (%s) RETURNING id', [telegram_id]) self.conn.commit() - return id + return self.cur.fetchone()[0] def find_user(self, telegram_id: int) -> int | None: """Get a user's telegram id and return its database id.""" @@ -38,9 +38,9 @@ class Database: def add_feed(self, url: str) -> int: """Add a feed to the database and return its id.""" self.log.debug('add_feed(url=\'%s\')', url) - id = self.cur.execute('INSERT INTO feeds (url) VALUES (%s) RETURNING id', [url]) + self.cur.execute('INSERT INTO feeds (url) VALUES (%s) RETURNING id', [url]) self.conn.commit() - return id + return self.cur.fetchone()[0] def find_feed_by_url(self, url: str) -> int | None: """Find feed ID by url.""" @@ -121,7 +121,7 @@ class Database: subscribers = self.cur.fetchall() return list(map(lambda x: x['telegram_id'], subscribers)) - def find_feeds(self) -> list[psycopg2.extras.DictRow]: + def find_feeds(self) -> list[DictRow]: """Get a list of feeds.""" self.log.debug('find_feeds()') self.cur.execute('SELECT * FROM feeds')