Add thread creation & deletion
This commit is contained in:
47
db/sqlite.py
47
db/sqlite.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user