fix: fix database ci

This commit is contained in:
EstrellaXD
2023-06-15 15:36:14 +08:00
parent e4d34f0e42
commit a5611129d6
4 changed files with 16 additions and 23 deletions

View File

@@ -1,9 +1,6 @@
import logging
from module.database.orm import Connector
from module.ab_decorator import locked
from module.database.connector import DataConnector
from module.models import BangumiData
from module.conf import DATA_PATH
@@ -91,26 +88,10 @@ class BangumiDatabase(Connector):
location = {"title_raw": title_raw}
set_value = {"poster_link": poster_link}
self.update.value(location, set_value)
# self._cursor.execute(
# """
# UPDATE bangumi
# SET poster_link = :poster_link
# WHERE title_raw = :title_raw
# """,
# {"poster_link": poster_link, "title_raw": title_raw},
# )
# self._conn.commit()
logger.debug(f"[Database] Update {title_raw} poster_link to {poster_link}.")
def delete_one(self, _id: int):
self.delete.one(_id)
# self._cursor.execute(
# """
# DELETE FROM bangumi WHERE id = :id
# """,
# {"id": _id},
# )
# self._conn.commit()
logger.debug(f"[Database] Delete bangumi id: {_id}.")
def delete_all(self):
@@ -122,8 +103,6 @@ class BangumiDatabase(Connector):
def search_id(self, _id: int) -> BangumiData | None:
dict_data = self.select.one(conditions={"id": _id})
# condition = {"id": _id}
# dict_data = self._search_data(table_name=self.__table_name, condition=condition)
if dict_data is None:
logger.warning(f"[Database] Cannot find bangumi id: {_id}.")
return None

View File

@@ -57,3 +57,6 @@ class Connector:
if keys:
return [dict(zip(keys, data)) for data in datas]
return [dict(zip(self._columns, data)) for data in datas]
def fetch(self):
return self._cursor.fetchall()

View File

@@ -9,6 +9,15 @@ class Update:
self._table_name = table_name
self._example_data = data
def __table_exists(self) -> bool:
self._connector.execute(
f"""
SELECT name FROM sqlite_master
WHERE type='table' AND name='{self._table_name}'
"""
)
return self._connector.fetch() is not None
def table(self):
columns = ", ".join(
[
@@ -18,8 +27,9 @@ class Update:
)
create_table_sql = f"CREATE TABLE IF NOT EXISTS {self._table_name} ({columns});"
self._connector.execute(create_table_sql)
logger.debug(f"Create table {self._table_name}.")
self._connector.execute(f"PRAGMA table_info({self._table_name})")
existing_columns = self._connector._columns
existing_columns = [x[1] for x in self._connector.fetch()]
for key, value in self._example_data.items():
if key not in existing_columns:
insert_column = self.__python_to_sqlite_type(value)
@@ -27,7 +37,7 @@ class Update:
value = "NULL"
add_column_sql = f"ALTER TABLE {self._table_name} ADD COLUMN {key} {insert_column} DEFAULT {value};"
self._connector.execute(add_column_sql)
logger.debug(f"Create / Update table {self._table_name}.")
logger.debug(f"Update table {self._table_name}.")
def one(self, data: dict) -> bool:
_id = data["id"]