Reputation: 27684
Assume only two columns(name and id) are needed from a table. I would code something like below:
session.query(User.id, User.name).all()
But if the column names are dynamic,
def get_data(table, columns):
return session.query(*(getattr(table, column) for column in columns)).all()
But the above one looks ugly. Is there a better recommended way?
Upvotes: 9
Views: 9667