2021.11 #49

Manually merged
edraft merged 10 commits from 2021.11 into master 2021-11-30 12:03:04 +01:00
Showing only changes of commit de22e79b71 - Show all commits

View File

@ -1,8 +1,6 @@
from typing import Optional from typing import Optional
import mysql.connector as sql import mysql.connector as sql
from cpl_core.console.console import Console
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
from cpl_core.database.connection.database_connection_abc import \ from cpl_core.database.connection.database_connection_abc import \
DatabaseConnectionABC DatabaseConnectionABC
from cpl_core.database.database_settings import DatabaseSettings from cpl_core.database.database_settings import DatabaseSettings
@ -30,7 +28,6 @@ class DatabaseConnection(DatabaseConnectionABC):
return self._cursor return self._cursor
def connect(self, database_settings: DatabaseSettings): def connect(self, database_settings: DatabaseSettings):
try:
connection = sql.connect( connection = sql.connect(
host=database_settings.host, host=database_settings.host,
user=database_settings.user, user=database_settings.user,
@ -40,7 +37,8 @@ class DatabaseConnection(DatabaseConnectionABC):
buffered=database_settings.buffered, buffered=database_settings.buffered,
auth_plugin=database_settings.auth_plugin auth_plugin=database_settings.auth_plugin
) )
connection.cursor().execute(f'CREATE DATABASE IF NOT EXISTS `{database_settings.database}`;') connection.cursor().execute(
f'CREATE DATABASE IF NOT EXISTS `{database_settings.database}`;')
self._database = sql.connect( self._database = sql.connect(
host=database_settings.host, host=database_settings.host,
user=database_settings.user, user=database_settings.user,
@ -52,11 +50,3 @@ class DatabaseConnection(DatabaseConnectionABC):
auth_plugin=database_settings.auth_plugin auth_plugin=database_settings.auth_plugin
) )
self._cursor = self._database.cursor() self._cursor = self._database.cursor()
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line(f'[{__name__}] Connected to database')
Console.set_foreground_color(ForegroundColorEnum.default)
except Exception as e:
Console.set_foreground_color(ForegroundColorEnum.red)
Console.write_line(f'[{__name__}] Database connection failed -> {e}')
Console.set_foreground_color(ForegroundColorEnum.default)
exit()