Implement custom config class; get SQLAlchemy database URI from config

This commit is contained in:
Lexi / Zoe 2022-04-15 01:49:41 +02:00
parent 31df889dcb
commit 04d434b4a3
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
7 changed files with 68 additions and 13 deletions

View file

@ -0,0 +1,32 @@
import yaml
from flask import Config as BaseConfig
from .defaults import DefaultConfig
class Config(BaseConfig):
"""
Custom config class for the Flask application.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Set app-specific default values
self.from_object(DefaultConfig)
def from_yaml(self, filename: str, *, silent: bool = False) -> bool:
"""
Update config from a YAML file.
"""
return self.from_file(filename, load=yaml.safe_load, silent=silent)
# Properties for type safe access to config values
@property
def sqlalchemy_database_uri(self) -> str:
return self.get('SQLALCHEMY_DATABASE_URI')
@property
def sqlalchemy_echo(self) -> bool:
return bool(self.get('SQLALCHEMY_ECHO'))