Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

query.Iterator.reverse #142

Closed Jaymon closed 9 months ago

Jaymon commented 3 years ago

let's say you have 150 rows in a db, and you want to grab the last 50 descending, and then reverse them, it would make sense to do something like:

reversed(q.desc_pk())

But that won't give you the last 50 rows in ascending order, it will actually give you the first 50 rows in ascending order because reversed triggers the Iterator.reverse() method, which currently does this:

def reverse(self):
        for f in self.query.fields_sort:
            f.direction = -f.direction
        self.reset()

I'm thinking that's not what we want it to do? It definitely violates the principal of least surprise.

Jaymon commented 9 months ago

Iterator no longer has a reverse method, all of the sorting should be handled by the actual query. I think this is more consistent