Switched mysql package

This commit is contained in:
Sven Heidemann 2023-10-12 20:11:14 +02:00
parent affbbc822d
commit 2d8ecd424a
6 changed files with 31 additions and 32 deletions

View File

@ -3,8 +3,8 @@
"Name": "cpl-core",
"Version": {
"Major": "2023",
"Minor": "4",
"Micro": "0.post5"
"Minor": "10",
"Micro": "0"
},
"Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -18,7 +18,6 @@
"Dependencies": [
"art>=5.9",
"colorama>=0.4.6",
"mysql-connector>=2.2.9",
"psutil>=5.9.4",
"packaging>=23.0",
"pynput>=1.7.6",
@ -26,7 +25,8 @@
"tabulate>=0.9.0",
"termcolor>=2.2.0",
"watchdog>=3.0.0",
"wheel>=0.40.0"
"wheel>=0.40.0",
"mysql-connector-python==8.1.0"
],
"DevDependencies": [
"Sphinx==5.0.2",

View File

@ -25,27 +25,27 @@ class DatabaseConnection(DatabaseConnectionABC):
def cursor(self) -> MySQLCursorBuffered:
return self._cursor
def connect(self, database_settings: DatabaseSettings):
def connect(self, settings: DatabaseSettings):
connection = sql.connect(
host=database_settings.host,
port=database_settings.port,
user=database_settings.user,
passwd=CredentialManager.decrypt(database_settings.password),
charset=database_settings.charset,
use_unicode=database_settings.use_unicode,
buffered=database_settings.buffered,
auth_plugin=database_settings.auth_plugin,
host=settings.host,
port=settings.port,
user=settings.user,
passwd=CredentialManager.decrypt(settings.password),
charset=settings.charset,
use_unicode=settings.use_unicode,
buffered=settings.buffered,
auth_plugin=settings.auth_plugin,
)
connection.cursor().execute(f"CREATE DATABASE IF NOT EXISTS `{database_settings.database}`;")
connection.cursor().execute(f"CREATE DATABASE IF NOT EXISTS `{settings.database}`;")
self._database = sql.connect(
host=database_settings.host,
port=database_settings.port,
user=database_settings.user,
passwd=CredentialManager.decrypt(database_settings.password),
db=database_settings.database,
charset=database_settings.charset,
use_unicode=database_settings.use_unicode,
buffered=database_settings.buffered,
auth_plugin=database_settings.auth_plugin,
host=settings.host,
port=settings.port,
user=settings.user,
passwd=CredentialManager.decrypt(settings.password),
db=settings.database,
charset=settings.charset,
use_unicode=settings.use_unicode,
buffered=settings.buffered,
auth_plugin=settings.auth_plugin,
)
self._cursor = self._database.cursor()

View File

@ -13,10 +13,10 @@ class DatabaseSettings(ConfigurationModelABC):
user: str = None,
password: str = None,
database: str = None,
charset: str = None,
use_unicode: bool = None,
buffered: bool = None,
auth_plugin: str = None,
charset: str = "utf8mb4",
use_unicode: bool = False,
buffered: bool = False,
auth_plugin: str = "caching_sha2_password",
):
ConfigurationModelABC.__init__(self)

View File

@ -20,7 +20,6 @@
"Database": "sh_cpl",
"Charset": "utf8mb4",
"UseUnicode": "true",
"Buffered": "true",
"AuthPlugin": "mysql_native_password"
"Buffered": "true"
}
}

View File

@ -3,5 +3,5 @@ from cpl_core.database.context import DatabaseContext
class DBContext(DatabaseContext):
def __init__(self, db_settings: DatabaseSettings):
DatabaseContext.__init__(self, db_settings)
def __init__(self):
DatabaseContext.__init__(self)

View File

@ -21,7 +21,6 @@ class Startup(StartupABC):
) -> ConfigurationABC:
configuration.add_environment_variables("PYTHON_")
configuration.add_environment_variables("CPL_")
configuration.parse_console_arguments()
configuration.add_json_file(f"appsettings.json")
configuration.add_json_file(f"appsettings.{configuration.environment.environment_name}.json")
configuration.add_json_file(f"appsettings.{configuration.environment.host_name}.json", optional=True)
@ -34,6 +33,7 @@ class Startup(StartupABC):
self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC
) -> ServiceProviderABC:
# Create and connect to database
self._configuration.parse_console_arguments(services)
db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings)
services.add_db_context(DBContext, db_settings)