From b1773a4b818512a8b2cb1e4c68690758bc981532 Mon Sep 17 00:00:00 2001 From: BryantHe Date: Tue, 30 May 2023 20:22:54 +0800 Subject: [PATCH] fix bug 6 --- chassis/config.py | 8 +++++--- chassis/db_context.py | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/chassis/config.py b/chassis/config.py index cbddbc7..2d29586 100644 --- a/chassis/config.py +++ b/chassis/config.py @@ -16,9 +16,11 @@ class Config: # 指定数据库 DEFAULT_DATABASE_URI = os.getenv('DEFAULT_DATABASE_URI') READONLY_DATABASE_URI = os.getenv('READONLY_DATABASE_URI') - const.DB_CONFIG_ITEM = { - const.DEFAULT_DB_KEY: DEFAULT_DATABASE_URI, - const.READONLY_DB_KEY: READONLY_DATABASE_URI, + DB_CONFIG_ITEM = { + const.DB_CONFIG_ITEM: { + const.DEFAULT_DB_KEY: DEFAULT_DATABASE_URI, + const.READONLY_DB_KEY: READONLY_DATABASE_URI, + } } STATSD_PREFIX = os.getenv('STATSD_PREFIX') diff --git a/chassis/db_context.py b/chassis/db_context.py index b2be323..5ca122a 100644 --- a/chassis/db_context.py +++ b/chassis/db_context.py @@ -7,11 +7,11 @@ from chassis.consts import const engines = {} -def init_engine(config): - if config: - databases = getattr(config, const.DB_CONFIG_ITEM) +def init_engine(config_item): + if config_item: + databases = config_item[const.DB_CONFIG_ITEM] else: - databases = getattr(Config, const.DB_CONFIG_ITEM) + databases = Config.DB_CONFIG_ITEM[const.DB_CONFIG_ITEM] for db_key, db_url in databases.items(): engine = create_engine(db_url, logging_name=db_key, poolclass=None, pool_size=5, max_overflow=20, pool_recycle=3600,