creating db if not existing
This commit is contained in:
parent
6f507b8d29
commit
3bb98edef4
1 changed files with 24 additions and 1 deletions
|
@ -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()
|
||||
|
|
Reference in a new issue