mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 18:04:32 +02:00
Added table.rows_where(where, args) method
This commit is contained in:
parent
72a6f430df
commit
f70e35c9bb
3 changed files with 36 additions and 1 deletions
|
|
@ -365,9 +365,15 @@ class Table:
|
|||
|
||||
@property
|
||||
def rows(self):
|
||||
return self.rows_where()
|
||||
|
||||
def rows_where(self, where=None, where_args=None):
|
||||
if not self.exists:
|
||||
return []
|
||||
cursor = self.db.conn.execute("select * from [{}]".format(self.name))
|
||||
sql = "select * from [{}]".format(self.name)
|
||||
if where is not None:
|
||||
sql += " where " + where
|
||||
cursor = self.db.conn.execute(sql, where_args or [])
|
||||
columns = [c[0] for c in cursor.description]
|
||||
for row in cursor:
|
||||
yield dict(zip(columns, row))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue