fix return values in add_user and add_feed methods
This commit is contained in:
parent
f11b0b91af
commit
5d0a6843b6
10
database.py
10
database.py
|
@ -22,9 +22,9 @@ class Database:
|
||||||
def add_user(self, telegram_id: int) -> int:
|
def add_user(self, telegram_id: int) -> int:
|
||||||
"""Add a user's telegram id to the database and return its database id."""
|
"""Add a user's telegram id to the database and return its database id."""
|
||||||
self.log.debug('add_user(telegram_id=\'%s\')', telegram_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()
|
self.conn.commit()
|
||||||
return id
|
return self.cur.fetchone()[0]
|
||||||
|
|
||||||
def find_user(self, telegram_id: int) -> int | None:
|
def find_user(self, telegram_id: int) -> int | None:
|
||||||
"""Get a user's telegram id and return its database id."""
|
"""Get a user's telegram id and return its database id."""
|
||||||
|
@ -38,9 +38,9 @@ class Database:
|
||||||
def add_feed(self, url: str) -> int:
|
def add_feed(self, url: str) -> int:
|
||||||
"""Add a feed to the database and return its id."""
|
"""Add a feed to the database and return its id."""
|
||||||
self.log.debug('add_feed(url=\'%s\')', url)
|
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()
|
self.conn.commit()
|
||||||
return id
|
return self.cur.fetchone()[0]
|
||||||
|
|
||||||
def find_feed_by_url(self, url: str) -> int | None:
|
def find_feed_by_url(self, url: str) -> int | None:
|
||||||
"""Find feed ID by url."""
|
"""Find feed ID by url."""
|
||||||
|
@ -121,7 +121,7 @@ class Database:
|
||||||
subscribers = self.cur.fetchall()
|
subscribers = self.cur.fetchall()
|
||||||
return list(map(lambda x: x['telegram_id'], subscribers))
|
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."""
|
"""Get a list of feeds."""
|
||||||
self.log.debug('find_feeds()')
|
self.log.debug('find_feeds()')
|
||||||
self.cur.execute('SELECT * FROM feeds')
|
self.cur.execute('SELECT * FROM feeds')
|
||||||
|
|
Loading…
Reference in a new issue