summaryrefslogtreecommitdiff
path: root/DBcm.py
blob: afe23911f9a0ec0773f04297ae24b9dc13fcd9aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import mysql.connector


class UseDatabase:

    def __init__(self, config: dict) -> None:
        self.configuration = config

    def __enter__(self) -> 'cursor':
        self.conn = mysql.connector.connect(**self.configuration)
        self.cursor = self.conn.cursor()
        return self.cursor

    def __exit__(self, exc_type, exc_value, exc_trace) -> None:
        self.conn.commit()
        self.cursor.close()
        self.conn.close()