-
Notifications
You must be signed in to change notification settings - Fork 1
/
skippersist.py
25 lines (19 loc) · 921 Bytes
/
skippersist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import aiosqlite, asyncio
from sql import aioSQL
class SkipPersist(aioSQL):
_aioSQL__name = "skip"
_aioSQL__setup = "user int"
async def toggle(self, cursor, user):
c = await cursor.execute(f'SELECT user FROM {self._aioSQL__name} WHERE user=?', (user,))
data = await c.fetchall()
if data: await cursor.execute(f'DELETE FROM {self._aioSQL__name} WHERE user=?', (user,))
else: await cursor.execute(f'INSERT INTO {self._aioSQL__name} VALUES (?)', (user,))
return await self.get(cursor, user)
async def get(self, cursor, user):
c = await cursor.execute(f'SELECT user FROM {self._aioSQL__name} WHERE user=?', (user,))
data = await c.fetchall()
return bool(data)
async def get_all(self, cursor):
c = await cursor.execute(f'SELECT * FROM {self._aioSQL__name}')
data = await c.fetchall()
return [x[0] for x in data]