lint con ruff
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import logging
|
||||
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def connetti_db(cfg: object) -> object:
|
||||
"""
|
||||
Establishes a connection to a MySQL database.
|
||||
@@ -21,14 +23,10 @@ def connetti_db(cfg: object) -> object:
|
||||
A MySQL connection object if the connection is successful, otherwise None.
|
||||
"""
|
||||
try:
|
||||
conn = mysql.connector.connect(user=cfg.dbuser,
|
||||
password=cfg.dbpass,
|
||||
host=cfg.dbhost,
|
||||
port=cfg.dbport,
|
||||
database=cfg.dbname)
|
||||
conn = mysql.connector.connect(user=cfg.dbuser, password=cfg.dbpass, host=cfg.dbhost, port=cfg.dbport, database=cfg.dbname)
|
||||
conn.autocommit = True
|
||||
logger.info("Connected")
|
||||
return conn
|
||||
except Error as e:
|
||||
logger.error(f"Database connection error: {e}")
|
||||
raise # Re-raise the exception to be handled by the caller
|
||||
raise # Re-raise the exception to be handled by the caller
|
||||
|
||||
Reference in New Issue
Block a user