forked from s_ranjbar/city_retrofit
40 lines
974 B
Python
40 lines
974 B
Python
|
"""
|
||
|
DBFactory performs database create, delete and update operations
|
||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||
|
Copyright © 2022 Concordia CERC group
|
||
|
Project CoderPeter Yefi peteryefi@gmail.com
|
||
|
"""
|
||
|
from persistence import CityRepo
|
||
|
|
||
|
|
||
|
class DBFactory:
|
||
|
"""
|
||
|
DBFactory class
|
||
|
"""
|
||
|
|
||
|
def __init__(self, city, db_name, app_env):
|
||
|
self._city = city
|
||
|
self._city_repo = CityRepo(db_name=db_name, app_env=app_env)
|
||
|
|
||
|
def persist_city(self):
|
||
|
"""
|
||
|
Persist city into postgres database
|
||
|
"""
|
||
|
return self._city_repo.insert(self._city)
|
||
|
|
||
|
def update_city(self, city_id, city):
|
||
|
"""
|
||
|
Update an existing city in postgres database
|
||
|
:param city_id: the id of the city to update
|
||
|
:param city: the updated city object
|
||
|
"""
|
||
|
return self._city_repo.update(city_id, city)
|
||
|
|
||
|
def delete_city(self, city_id):
|
||
|
"""
|
||
|
Deletes a single city from postgres
|
||
|
:param city_id: the id of the city to get
|
||
|
"""
|
||
|
self._city_repo.delete_city(city_id)
|
||
|
|