Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order_by mechanism #76

Closed
metab0t opened this issue Jan 14, 2020 · 4 comments
Closed

order_by mechanism #76

metab0t opened this issue Jan 14, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@metab0t
Copy link

metab0t commented Jan 14, 2020

In some cases, I want to iterate rows in a table with ORDER BY clause. It would be nice to have a rows_order_by function similar to rows_where.
In a more general case, rows_filter function might be added to allow more customized filtering to iterate rows.

@simonw
Copy link
Owner

simonw commented Apr 16, 2020

I think a neat way to do this would be with an optional argument for .rows_where():

rows = db["table"].rows_where("age > 10", order_by="age desc")

If you want everything you can use this:

rows = db["table"].rows_where(order_by="age desc")

It's a tiny bit weird calling .rows_where() without a where clause, but I think it makes sense here - especially since .rows is a property that can't take any arguments - though under the hood it actually does this:

@property
def rows(self):
return self.rows_where()
def rows_where(self, where=None, where_args=None):
if not self.exists():
return []
sql = "select * from [{}]".format(self.name)

@simonw simonw added the enhancement New feature or request label Apr 16, 2020
@simonw simonw changed the title Add rows_order_by function order_by mechanism Apr 16, 2020
@simonw simonw closed this as completed in 125c625 Apr 16, 2020
@simonw
Copy link
Owner

simonw commented Apr 16, 2020

Released in 2.6

@simonw
Copy link
Owner

simonw commented Apr 16, 2020

simonw added a commit to simonw/big-local-datasette that referenced this issue Apr 16, 2020
I changed the logic for looping through projects and ensured that
if your local copy of a DB is 0 bytes we always fetch it even if
the hash appears to be unchanged.

Takes advantage of simonw/sqlite-utils#76
@metab0t
Copy link
Author

metab0t commented Apr 16, 2020

Thanks for your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants