예제 #1
0
 async def get(self, chat_id: int) -> Chat:
     async with self.pool.acquire() as conn:
         row = await conn.fetchrow("SELECT * FROM chats WHERE id = $1", chat_id)
     if row:
         return Chat(row['id'], json.loads(row['tags']), json.loads(row['permissions'] or '{}'), row['locked'])
     else:
         return await self.add(chat_id)
예제 #2
0
 async def add(self, chat_id: int) -> Optional[Chat]:
     async with self.pool.acquire() as conn:
         await conn.execute("""
         INSERT INTO chats 
         VALUES ($1, '{}') 
         ON CONFLICT DO NOTHING
         """, chat_id)
     return Chat(chat_id, {})
예제 #3
0
 async def add(self, chat_id: int) -> Optional[Chat]:
     """Add a Chat to the DB or return an existing one.
     Args:
         chat_id: The id of the chat
     Returns: The chat Document
     """
     async with self.pool.acquire() as conn:
         await conn.execute("INSERT INTO chats VALUES ($1, '{}') ON CONFLICT DO NOTHING", chat_id)
     return Chat(chat_id, {})
예제 #4
0
 async def get(self, chat_id: int) -> Chat:
     """Return a Chat document
     Args:
         chat_id: The id of the chat
     Returns: The chat Document
     """
     async with self.pool.acquire() as conn:
         row = await conn.fetchrow("SELECT * FROM chats WHERE id = $1", chat_id)
     if row:
         return Chat(row['id'], json.loads(row['tags']))
     else:
         return await self.add(chat_id)