.rows_where(..., order_by=) argument, closes #76

This commit is contained in:
Simon Willison 2020-04-15 20:12:55 -07:00
commit 125c625fbc
3 changed files with 42 additions and 2 deletions

View file

@ -437,12 +437,14 @@ class Queryable:
def rows(self):
return self.rows_where()
def rows_where(self, where=None, where_args=None):
def rows_where(self, where=None, where_args=None, order_by=None):
if not self.exists():
return []
sql = "select * from [{}]".format(self.name)
if where is not None:
sql += " where " + where
if order_by is not None:
sql += " order by " + order_by
cursor = self.db.conn.execute(sql, where_args or [])
columns = [c[0] for c in cursor.description]
for row in cursor: