"""MySQL config.""" from dataclasses import dataclass from sqlalchemy import URL, Engine, create_engine from .db_config import DBConfig @dataclass class MySQLConfig(DBConfig): """MySQL connection configuration.""" user: str password: str database: str host: str = '127.0.0.1' port: int = 3306 def get_engine(self) -> Engine: """Get SQLAlchemy engine.""" return create_engine(self.get_url()) def get_url(self) -> URL: """Get a connection URL.""" return URL.create( 'mysql+pymysql', host=self.host, port=self.port, username=self.user, password=self.password, database=self.database, ) def get_vendor(self) -> str: """Get database vendor.""" return 'mysql' def __repr__(self) -> str: """Represent the config as a string.""" return f'{self.get_url()}'