database_module #17

Merged
Miroslavsckaya merged 20 commits from database_interaction into master 2022-05-29 20:19:18 +00:00
Showing only changes of commit dc3889635e - Show all commits

View file

@ -8,6 +8,7 @@ class Database():
self.cur.execute('CREATE TABLE IF NOT EXISTS subscriptions (user_id INTEGER, feed_id INTEGER, FOREIGN KEY(user_id) REFERENCES users(id), FOREIGN KEY(feed_id) REFERENCES feeds(id))')
self.cur.execute('CREATE UNIQUE INDEX IF NOT EXISTS subscriptions_index ON subscriptions (user_id, feed_id)')
self.cur.execute('CREATE TABLE IF NOT EXISTS feeds_last_items (feed_id INTEGER, url TEXT NOT NULL UNIQUE, title TEXT, description TEXT, date NUMERIC, FOREIGN KEY(feed_id) REFERENCES feeds(id))')
self.cur.execute('CREATE UNIQUE INDEX IF NOT EXISTS feed_item_index ON feeds_last_items (feed_id, date)')
def add_user(self, telegram_id: str) -> int:
self.cur.execute('INSERT INTO users (telegram_id) VALUES (?)', [telegram_id])
@ -38,16 +39,14 @@ class Database():
self.cur.execute('DELETE FROM feeds WHERE id = ?', [feed_id])
self.conn.commit()
def get_feeds(self) -> list:
def find_feeds(self) -> list:
self.cur.execute('SELECT * FROM feeds')
return self.cur.fetchall()
def get_user_feeds(self, user_id: int) -> list:
def find_user_feeds(self, user_id: int) -> list:
self.cur.execute('SELECT * FROM feeds WHERE id IN (SELECT feed_id FROM subscriptions WHERE user_id = ?)', [user_id])
return self.cur.fetchall()
def get_feed_items():
pass
def storing_feed_content():
pass
def find_feed_items(self, feed_id: int) -> list:
self.cur.execute('SELECT * FROM feeds_last_items WHERE feed_id = (?)', [feed_id])
return self.cur.fetchall()