refactor: clean left os.path code

This commit is contained in:
100gle
2023-07-03 21:41:58 +08:00
parent 653119dbad
commit 840ffd8a4a

View File

@@ -1,4 +1,5 @@
import os
from os import PathLike
from pathlib import Path
import sqlite3
from .delete import Delete
@@ -10,10 +11,13 @@ from module.conf import DATA_PATH
class Connector:
def __init__(self, table_name: str, data: dict, database: str = DATA_PATH):
def __init__(
self, table_name: str, data: dict, database: PathLike[str] | Path = DATA_PATH
):
# Create folder if not exists
if not os.path.exists(os.path.dirname(DATA_PATH)):
os.makedirs(os.path.dirname(DATA_PATH))
if isinstance(database, PathLike):
database = Path(database)
database.parent.mkdir(parents=True, exist_ok=True)
self._conn = sqlite3.connect(database)
self._cursor = self._conn.cursor()