import sqlite3
class DatabaseConnection:
def __init__(self,host):
self.connection = None
self.host = host
def __enter__(self):
self.connection = sqlite3.connect(self.host)
return self.connection
def __exit__(self, exc_type, exc_val, exc_tb): #parameters in case of exception
if exc_tb or exc_val or exc_type: # if one of thos erros happen
self.connection.close()
else:
self.connection.commit()
self.connection.close()