From 3bb98edef4c7cb95bbd8a145ae5aedbd1d1c4920 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 3 Jun 2021 08:30:17 +0200 Subject: [PATCH] creating db if not existing --- src/utils/db.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/utils/db.py b/src/utils/db.py index a3f49ca..18eb5b2 100644 --- a/src/utils/db.py +++ b/src/utils/db.py @@ -1,3 +1,26 @@ import sqlite3 +from pathlib import Path -con = sqlite3.connect('../db/bot.sqlite3') +class Database(): + + def __init__(self): + path = Path("src/db/bot.sqlite3").absolute() + if not self.isDatabaseExists(path): + self.createDB(path) + self.con = sqlite3.connect(path) + print("DB Open") + + def isDatabaseExists(self, path): + try: + Path(path).resolve(strict = True) + except FileNotFoundError: + return False + else: + return True + + def createDB(self, path): + print("Creating DB...") + open(path, "x") + + +Database()