Table works
This commit is contained in:
@ -125,8 +125,8 @@ class DB():
|
||||
id:str|None=None, sender:str|None=None, recipient:str|None=None,
|
||||
processed:bool|None=None,
|
||||
time_after:int|None=None, time_before:int|None=None,
|
||||
limit:int=20, offset:int=0
|
||||
) -> Generator[RowObject, None, None]:
|
||||
limit:int=20, offset:int=0, _count_only:bool=False
|
||||
) -> Generator[RowObject|int, None, None]:
|
||||
|
||||
where = []
|
||||
params = {
|
||||
@ -153,11 +153,29 @@ class DB():
|
||||
where_clause = ""
|
||||
|
||||
with self.db:
|
||||
for row in self.db.execute(
|
||||
"SELECT * FROM Messages {} ORDER BY time DESC LIMIT :lim OFFSET :off".format(where_clause),
|
||||
params
|
||||
):
|
||||
yield self._create_row_object(row)
|
||||
if _count_only:
|
||||
count = self.db.execute(
|
||||
"SELECT COUNT(*) as count FROM Messages {}".format(where_clause),
|
||||
params
|
||||
).fetchone()
|
||||
|
||||
yield count['count']
|
||||
else:
|
||||
for row in self.db.execute(
|
||||
"SELECT * FROM Messages {} ORDER BY time DESC LIMIT :lim OFFSET :off".format(where_clause),
|
||||
params
|
||||
):
|
||||
yield self._create_row_object(row)
|
||||
|
||||
def __len__(self) -> int:
|
||||
return self.len()
|
||||
|
||||
def len(self, **kwargs) -> int:
|
||||
"""
|
||||
See `DB.iterate` for possible values of `kwargs`.
|
||||
"""
|
||||
kwargs['_count_only'] = True
|
||||
return next(self.iterate(**kwargs))
|
||||
|
||||
def _create_row_object(self, row:sqlite3.Row) -> RowObject:
|
||||
return RowObject(
|
||||
|
Reference in New Issue
Block a user