def delete_postal_code(self, fields_map: Dict): Session = sessionmaker(bind=self.engine) session = Session() accessor = PostalCodeAccessor(session) pri_map = {x: fields_map[x] for x in self.pri_keys if x in fields_map} accessor.delete(pri_map) session.close()
def get_postal_code(self, filter_map: Dict): Session = sessionmaker(bind=self.engine) session = Session() accessor = PostalCodeAccessor(session) postal_code = accessor.read(filter_map) session.close() return postal_code
def insert_postal_code(self, fields_map: Dict): Session = sessionmaker(bind=self.engine) session = Session() accessor = PostalCodeAccessor(session) new_postal_code = PostalCode() for k, v in fields_map.items(): setattr(new_postal_code, k, v) accessor.create(new_postal_code) session.close()
def get_land_use_from_location(self, location_key: LocationKey): Session = sessionmaker(bind=self.engine) session = Session() accessor = PostalCodeAccessor(session) postal_code = accessor.read({ "block": location_key.block, "road": location_key.road, "postal_code": location_key.postal_code }) session.close() return postal_code[0]["land_use_type"]
def get_coordinates(self, location_key: LocationKey): Session = sessionmaker(bind=self.engine) session = Session() accessor = PostalCodeAccessor(session) postal_code = accessor.read({ "block": location_key.block, "road": location_key.road, "postal_code": location_key.postal_code }) session.close() return postal_code[0]["latitude"], postal_code[0]["longitude"]
def is_shophouse(self, location_key: LocationKey): Session = sessionmaker(bind=self.engine) session = Session() accessor = PostalCodeAccessor(session) postal_code = accessor.read({ "block": location_key.block, "road": location_key.road, "postal_code": location_key.postal_code }) session.close() if postal_code and postal_code[0]["property_type"] == 'Shophouses': return True else: return False