30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from src.logging.get_logger import get_logger
|
|
from src.model.db.prefc_master import PrefcMasterModel
|
|
from src.repositories.base_repository import BaseRepository
|
|
|
|
logger = get_logger('都道府県マスタ取得')
|
|
|
|
|
|
class PrefcMasterRepository(BaseRepository):
|
|
|
|
FETCH_SQL = """\
|
|
SELECT DISTINCT
|
|
com_inst.prefc_cd AS prefc_cd,
|
|
mst_jis_pref.jis_pref_nm_kj AS prefc_name
|
|
FROM
|
|
src05.com_inst
|
|
JOIN src07.mst_jis_pref ON com_inst.prefc_cd = mst_jis_pref.jis_pref_cd and (select str_to_date(syor_date,'%Y%m%d') from src07.hdke_tbl) between STR_TO_DATE(CONCAT(eff_start_ym, '01'), '%Y%m%d') and LAST_DAY(STR_TO_DATE(CONCAT(eff_end_ym, '01'), '%Y%m%d'))
|
|
ORDER BY
|
|
prefc_cd
|
|
"""
|
|
|
|
def fetch_all(self) -> list[PrefcMasterModel]:
|
|
try:
|
|
result = self._database.execute_select(self.FETCH_SQL)
|
|
result_data = [res for res in result]
|
|
models = [PrefcMasterModel(**r) for r in result_data]
|
|
return models
|
|
except Exception as e:
|
|
logger.exception(f"DB Error : Exception={e.args}")
|
|
raise e
|