(Refactor) remove fucntion for creating DB file.
This commit is contained in:
@@ -29,3 +29,5 @@
|
|||||||
Added TOML configuration file.
|
Added TOML configuration file.
|
||||||
Updated paths of files and folders.
|
Updated paths of files and folders.
|
||||||
Updated my name to my fullname and release years.
|
Updated my name to my fullname and release years.
|
||||||
|
** 1.0.2 <2023-01-15>
|
||||||
|
Refactor the database class and remove function for the creating file.
|
||||||
|
|||||||
@@ -29,22 +29,8 @@ class DataBase:
|
|||||||
def __init__(self, PATH: str = "user.db", TABLE: str = "animes"):
|
def __init__(self, PATH: str = "user.db", TABLE: str = "animes"):
|
||||||
"""Initialising the connection information."""
|
"""Initialising the connection information."""
|
||||||
self.PATH, self.TABLE = PATH, TABLE
|
self.PATH, self.TABLE = PATH, TABLE
|
||||||
self.database_is_exists()
|
|
||||||
self.create_table(self.TABLE)
|
self.create_table(self.TABLE)
|
||||||
|
|
||||||
def database_is_exists(self):
|
|
||||||
"""Creates DB file if not exists."""
|
|
||||||
try:
|
|
||||||
f = open(self.PATH, 'r')
|
|
||||||
f.close()
|
|
||||||
except FileNotFoundError:
|
|
||||||
f = open(self.PATH, 'w')
|
|
||||||
f.close()
|
|
||||||
except Exception as e:
|
|
||||||
print(f"{e=}")
|
|
||||||
finally:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def create_table(self, table):
|
def create_table(self, table):
|
||||||
"""Create a table in the DB."""
|
"""Create a table in the DB."""
|
||||||
connect = sqlite3.connect(self.PATH)
|
connect = sqlite3.connect(self.PATH)
|
||||||
|
|||||||
Reference in New Issue
Block a user