Add mark as non-linear division mannally
This commit is contained in:
26
db.py
26
db.py
@@ -14,12 +14,17 @@ user_id INT,
|
||||
key TEXT,
|
||||
PRIMARY KEY (chapter_id, user_id)
|
||||
);'''
|
||||
DIVISION_TABLE = '''CREATE TABLE division(
|
||||
division_id INT,
|
||||
is_linear BOOL,
|
||||
PRIMARY KEY(division_id)
|
||||
);'''
|
||||
|
||||
|
||||
class CwmDb:
|
||||
def __init__(self, db_path):
|
||||
self._db = sqlite3.connect(db_path, check_same_thread=False)
|
||||
self.version = Version(0, 0, 0, 0)
|
||||
self.version = Version(0, 0, 0, 1)
|
||||
if not self.__check_database():
|
||||
self.__create_table()
|
||||
|
||||
@@ -29,6 +34,8 @@ class CwmDb:
|
||||
if v is None:
|
||||
return False
|
||||
if v < self.version:
|
||||
if v < Version(0, 0, 0, 1):
|
||||
self._db.execute(DIVISION_TABLE)
|
||||
self.__update_exists_tables()
|
||||
self.__write_version()
|
||||
return True
|
||||
@@ -44,6 +51,7 @@ class CwmDb:
|
||||
def __write_version(self):
|
||||
self._db.execute('INSERT OR REPLACE INTO version VALUES (?, ?);', [
|
||||
'main', str(self.version)])
|
||||
self._db.commit()
|
||||
|
||||
def __read_version(self) -> Optional[Version]:
|
||||
if 'version' not in self._exist_tables:
|
||||
@@ -71,7 +79,23 @@ class CwmDb:
|
||||
cur = self._db.execute('SELECT chapter_id, user_id, key FROM key;')
|
||||
return {f'{i[0]}{i[1]}': i[2] for i in cur}
|
||||
|
||||
def commit(self):
|
||||
self._db.commit()
|
||||
|
||||
def get_key(self, chapter_id: int) -> List[str]:
|
||||
cur = self._db.execute('SELECT key FROM key WHERE chapter_id = ?;', [
|
||||
chapter_id])
|
||||
return [i[0] for i in cur]
|
||||
|
||||
def get_mark(self, division_id: int):
|
||||
cur = self._db.execute(
|
||||
'SELECT is_linear FROM division WHERE division_id = ?;',
|
||||
[division_id])
|
||||
for i in cur:
|
||||
return bool(i[0])
|
||||
return True
|
||||
|
||||
def set_mark(self, division_id: int, is_linear: bool):
|
||||
self._db.execute('INSERT OR REPLACE INTO division VALUES (?, ?);', [
|
||||
division_id, is_linear])
|
||||
self._db.commit()
|
||||
|
||||
Reference in New Issue
Block a user