Updated docs
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-core sh-edraft Common Python library
|
||||
cpl-core CPL core
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
CPL core package
|
||||
|
||||
:copyright: (c) 2020 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_core.database.connection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2023 sh-edraft.de'
|
||||
__version__ = '2022.12.1'
|
||||
__title__ = "cpl_core.database.connection"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de"
|
||||
__version__ = "2023.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,5 +24,5 @@ from collections import namedtuple
|
||||
from .database_connection import DatabaseConnection
|
||||
from .database_connection_abc import DatabaseConnectionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='1')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2023", minor="2", micro="0")
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from typing import Optional
|
||||
|
||||
import mysql.connector as sql
|
||||
from cpl_core.database.connection.database_connection_abc import \
|
||||
DatabaseConnectionABC
|
||||
from cpl_core.database.connection.database_connection_abc import DatabaseConnectionABC
|
||||
from cpl_core.database.database_settings import DatabaseSettings
|
||||
from cpl_core.utils.credential_manager import CredentialManager
|
||||
from mysql.connector.abstracts import MySQLConnectionAbstract
|
||||
@@ -10,8 +9,7 @@ from mysql.connector.cursor import MySQLCursorBuffered
|
||||
|
||||
|
||||
class DatabaseConnection(DatabaseConnectionABC):
|
||||
r"""Representation of the database connection
|
||||
"""
|
||||
r"""Representation of the database connection"""
|
||||
|
||||
def __init__(self):
|
||||
DatabaseConnectionABC.__init__(self)
|
||||
@@ -36,10 +34,9 @@ class DatabaseConnection(DatabaseConnectionABC):
|
||||
charset=database_settings.charset,
|
||||
use_unicode=database_settings.use_unicode,
|
||||
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(
|
||||
host=database_settings.host,
|
||||
port=database_settings.port,
|
||||
@@ -49,6 +46,6 @@ class DatabaseConnection(DatabaseConnectionABC):
|
||||
charset=database_settings.charset,
|
||||
use_unicode=database_settings.use_unicode,
|
||||
buffered=database_settings.buffered,
|
||||
auth_plugin=database_settings.auth_plugin
|
||||
auth_plugin=database_settings.auth_plugin,
|
||||
)
|
||||
self._cursor = self._database.cursor()
|
||||
|
||||
@@ -9,22 +9,24 @@ class DatabaseConnectionABC(ABC):
|
||||
r"""ABC for the :class:`cpl_core.database.connection.database_connection.DatabaseConnection`"""
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def server(self) -> MySQLConnectionAbstract: pass
|
||||
|
||||
def server(self) -> MySQLConnectionAbstract:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def cursor(self) -> MySQLCursorBuffered: pass
|
||||
|
||||
def cursor(self) -> MySQLCursorBuffered:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def connect(self, database_settings: DatabaseSettings):
|
||||
r"""Connects to a database by connection string
|
||||
|
||||
Parameter
|
||||
---------
|
||||
Parameter:
|
||||
connection_string: :class:`str`
|
||||
Database connection string, see: https://docs.sqlalchemy.org/en/14/core/engines.html
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user