Я работаю с MySQL, и мне нужно «перевести» запрос в Pony ORM.
У меня есть большая таблица «клиенты» с множеством столбцов, и моя проблема состоит в том, чтобы записать каждый столбец в методы работы с базой данных. Итак, у меня есть что-то вроде:
Код: Выделить всё
@db_session
def get_client_info_by(self, **criteria) -> Union[dict, None]:
"""Return client's info from database by specified criteria"""
if not criteria: # If no criteria provided, return None
return None
query = select(c for c in self.clients)
for attr, value in criteria.items(): # Add filters to the query based on the criteria
query = query.filter(lambda c: getattr(c, attr) == value)
client = query[:]
if client:
client_info = {
'id': client[0].id,
'first_name': client[0].first_name,
'last_name': client[0].last_name,
'type': client[0].type,
'language_id': client[0].language_id,
'country_id': client[0].country_id,
# a lot of other columns ... (about 50)
'created_at': client[0].created_at,
'updated_at': client[0].updated_at
}
return client_info
else:
return None
Подробнее здесь: https://stackoverflow.com/questions/784 ... n-pony-orm