mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Added db[table].rows iterator
This commit is contained in:
parent
62e1edeaf6
commit
3095f2e671
3 changed files with 26 additions and 0 deletions
|
|
@ -134,6 +134,15 @@ class Table:
|
|||
).fetchall()
|
||||
return [Column(*row) for row in rows]
|
||||
|
||||
@property
|
||||
def rows(self):
|
||||
if not self.exists:
|
||||
return []
|
||||
cursor = self.db.conn.execute("select * from [{}]".format(self.name))
|
||||
columns = [c[0] for c in cursor.description]
|
||||
for row in cursor:
|
||||
yield dict(zip(columns, row))
|
||||
|
||||
@property
|
||||
def pks(self):
|
||||
return [column.name for column in self.columns if column.is_pk]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue