feat: repositoryクラスでconnect-disconnectをしないように修正
This commit is contained in:
parent
4a6020c136
commit
485648879f
@ -53,7 +53,6 @@ class UltmarcDoctorRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, parameter: UltmarcDoctorSearchModel) -> list[UltmarcDoctorDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
# 文字列の検索を部分一致にするため、モデルをコピー。以降はこのコピーを使用する。
|
||||
clone_parameter = UltmarcDoctorSearchModel(**parameter.model_dump())
|
||||
where_clause = self.__build_condition(clone_parameter)
|
||||
@ -66,8 +65,6 @@ class UltmarcDoctorRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
def __build_condition(self, parameter: UltmarcDoctorSearchModel):
|
||||
where_clauses: list[SQLCondition] = []
|
||||
@ -187,7 +184,6 @@ class UltmarcDoctorRepository(BaseRepository):
|
||||
|
||||
def fetch_one(self, id) -> UltmarcDoctorInfoDBModel:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_ONE_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcDoctorInfoDBModel(**r) for r in result]
|
||||
@ -197,5 +193,3 @@ class UltmarcDoctorRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -31,7 +31,6 @@ class UltmarcDoctorWrkplaceHisRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, id) -> list[UltmarcDoctorWrkplaceHisDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcDoctorWrkplaceHisDBModel(**r) for r in result]
|
||||
@ -41,5 +40,3 @@ class UltmarcDoctorWrkplaceHisRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -30,7 +30,6 @@ class UltmarcDoctorWrkplaceRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, id) -> list[UltmarcDoctorWrkplaceDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcDoctorWrkplaceDBModel(**r) for r in result]
|
||||
@ -40,8 +39,6 @@ class UltmarcDoctorWrkplaceRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
FETCH_COUNT_SQL = """\
|
||||
SELECT COUNT(*) AS count
|
||||
@ -51,7 +48,6 @@ class UltmarcDoctorWrkplaceRepository(BaseRepository):
|
||||
|
||||
def fetch_count(self, id) -> UltmarcDoctorWrkplaceCountDBModel:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_COUNT_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcDoctorWrkplaceCountDBModel(**r) for r in result]
|
||||
@ -61,5 +57,3 @@ class UltmarcDoctorWrkplaceRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -39,7 +39,6 @@ class UltmarcInstRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, parameter: UltmarcInstSearchModel) -> list[UltmarcInstDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
# 文字列の検索を部分一致にするため、モデルをコピー。以降はこのコピーを使用する。
|
||||
clone_parameter = UltmarcInstSearchModel(**parameter.model_dump())
|
||||
where_clause = self.__build_condition(clone_parameter)
|
||||
@ -52,8 +51,6 @@ class UltmarcInstRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
def __build_condition(self, parameter: UltmarcInstSearchModel):
|
||||
where_clauses: list[SQLCondition] = []
|
||||
@ -188,7 +185,6 @@ class UltmarcInstRepository(BaseRepository):
|
||||
|
||||
def fetch_one(self, id) -> UltmarcInstInfoDBModel:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_ONE_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcInstInfoDBModel(**r) for r in result]
|
||||
@ -198,5 +194,3 @@ class UltmarcInstRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -18,7 +18,6 @@ class UltmarcInstTrtCourseRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, id) -> list[UltmarcInstTrtCourseDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
|
||||
@ -29,5 +28,3 @@ class UltmarcInstTrtCourseRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -18,7 +18,6 @@ class UltmarcSosietyRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, id) -> list[UltmarcSosietyDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcSosietyDBModel(**r) for r in result]
|
||||
@ -28,5 +27,3 @@ class UltmarcSosietyRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -20,7 +20,6 @@ class UltmarcSpecialistLicenseRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, id) -> UltmarcSpecialistLicenseDBModel:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
models = [UltmarcSpecialistLicenseDBModel(**r) for r in result]
|
||||
@ -30,5 +29,3 @@ class UltmarcSpecialistLicenseRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -18,7 +18,6 @@ class UltmarcDrTrtCourseRepository(BaseRepository):
|
||||
|
||||
def fetch_many(self, id) -> list[UltmarcDrTrtCourseDBModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, {'id': id})
|
||||
|
||||
@ -29,5 +28,3 @@ class UltmarcDrTrtCourseRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e.args}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -17,7 +17,6 @@ class UserMasterRepository(BaseRepository):
|
||||
|
||||
def fetch_one(self, parameter: dict) -> UserMasterModel:
|
||||
try:
|
||||
self._database.connect()
|
||||
query = self.FETCH_SQL
|
||||
result = self._database.execute_select(query, parameter)
|
||||
models = [UserMasterModel(**r) for r in result]
|
||||
@ -27,5 +26,3 @@ class UserMasterRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
@ -31,7 +31,6 @@ class WholesalerMasterRepository(BaseRepository):
|
||||
|
||||
def fetch_all(self) -> list[WholesalerMasterModel]:
|
||||
try:
|
||||
self._database.connect()
|
||||
result = self._database.execute_select(self.FETCH_SQL)
|
||||
result_data = [res for res in result]
|
||||
models = [WholesalerMasterModel(**r) for r in result_data]
|
||||
@ -39,5 +38,3 @@ class WholesalerMasterRepository(BaseRepository):
|
||||
except Exception as e:
|
||||
logger.exception(f"DB Error : Exception={e}")
|
||||
raise e
|
||||
finally:
|
||||
self._database.disconnect()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user