diff options
| author | Willem Renes <wrenes@gmail.com> | 2021-05-12 12:07:27 +0200 |
|---|---|---|
| committer | Willem Renes <wrenes@gmail.com> | 2021-05-12 12:07:27 +0200 |
| commit | 6dabf79eba1d9a2bcee77687785280cb9bdd38ac (patch) | |
| tree | 16d3113e79801b55ceae5d944986d85c5df2bc54 /DBcm.py | |
| parent | 20abdbd4c66ea086d809aea9be8a8aa8e3eba208 (diff) | |
| download | vsearchweb-6dabf79eba1d9a2bcee77687785280cb9bdd38ac.tar.gz vsearchweb-6dabf79eba1d9a2bcee77687785280cb9bdd38ac.zip | |
Diffstat (limited to 'DBcm.py')
| -rw-r--r-- | DBcm.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -0,0 +1,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() |
