mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Add 'get_states_list' and 'reset_all' methods
This commit is contained in:
parent
f321c69f46
commit
afde20eccd
1 changed files with 25 additions and 1 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
__all__ = ['RethinkDBStorage']
|
__all__ = ['RethinkDBStorage']
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import rethinkdb as r
|
import rethinkdb as r
|
||||||
|
|
@ -140,3 +139,28 @@ class RethinkDBStorage(BaseStorage):
|
||||||
await r.table(self._table).insert(
|
await r.table(self._table).insert(
|
||||||
{'id': chat, user: {'data': bucket}},
|
{'id': chat, user: {'data': bucket}},
|
||||||
conflict='update').run(conn)
|
conflict='update').run(conn)
|
||||||
|
|
||||||
|
async def get_states_list(self) -> typing.List[typing.Tuple[int]]:
|
||||||
|
"""
|
||||||
|
Get list of all stored chat's and user's
|
||||||
|
|
||||||
|
:return: list of tuples where first element is chat id and second is user id
|
||||||
|
"""
|
||||||
|
conn = await self.connection()
|
||||||
|
result = []
|
||||||
|
|
||||||
|
items = await r.table(self._table).get_all().run(conn).items
|
||||||
|
|
||||||
|
for item in items:
|
||||||
|
chat = int(item.pop('id'))
|
||||||
|
users = int(item.keys())
|
||||||
|
result.append((chat, users))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
async def reset_all(self):
|
||||||
|
"""
|
||||||
|
Reset states in DB
|
||||||
|
"""
|
||||||
|
conn = await self.connection()
|
||||||
|
await r.table(self._table).get_all().delete().run(conn)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue