I'm working with SqlAlchemy to query a database containing a list of events. Each event has a created time and an ari (amazon resource number). There's a maximum number of records I can get back from one function call, and I want to get back the records starting with the most recent first. To do this I need to manually pass in a lambda function that sorts the records properly; documentation for the argument is here:
cols (default=None):
A function which takes a DBObject class and returns a tuple of columns (or SQLAlchemy
expressions) used to compare it. This overrides the default sorting behaviour.
Example: key=lambda x: (x.created, x.ari)
As you can see, by default it sorts by x.created, then x.ari, both in ascending order. I actually need to do the opposite of this and sort by x.created, then x.ari, in descending order. Is there any way I can do this with just a lambda? Using sort() or sorted() is not really an option due to me using this pre-existing function.