Add thread creation & deletion

This commit is contained in:
David Hoppenbrouwers
2022-10-07 15:20:17 +02:00
parent 6f3b4de047
commit b96db0b905
8 changed files with 129 additions and 17 deletions

View File

@@ -16,8 +16,8 @@ class DB:
def get_thread(self, thread):
db = self._db()
title, text, author = db.execute('''
select title, text, name
title, text, author, author_id = db.execute('''
select title, text, name, author_id
from threads, users
where thread_id = ? and author_id = user_id
''',
@@ -30,7 +30,16 @@ class DB:
''',
(thread,)
).fetchall()
return title, text, author, comments
return title, text, author, author_id, comments
def get_thread_title(self, thread_id):
return self._db().execute('''
select title
from threads
where thread_id = ?
''',
(thread_id,)
).fetchone()
def get_comments(self, thread):
return self._db().execute('''
@@ -77,7 +86,6 @@ class DB:
).fetchone()
def set_user_private_info(self, user_id, about):
print('BROH', about)
db = self._db()
db.execute('''
update users
@@ -88,5 +96,36 @@ class DB:
)
db.commit()
def add_thread(self, author_id, forum_id, title, text, time):
db = self._db()
c = db.cursor()
c.execute('''
insert into threads (author_id, forum_id, title, text,
create_time, modify_time, update_time)
values (?, ?, ?, ?, ?, ?, ?)
''',
(author_id, forum_id, title, text, time, time, time)
)
rowid = c.lastrowid
db.commit()
return db.execute('''
select thread_id
from threads
where rowid = ?
''',
(rowid,)
).fetchone()
def delete_thread(self, thread_id):
db = self._db()
db.execute('''
delete
from threads
where thread_id = ?
''',
(thread_id,)
)
db.commit()
def _db(self):
return sqlite3.connect(self.conn)