async def get(self, index): async with self.pool.acquire() as conn: row = await conn.fetchrow(f"SELECT * FROM blacklists.{self.name} WHERE id = $1", index) if row: return BlacklistItem(row['id'], row['item'], row['retired']) else: return None
async def get_indices(self, indices): async with self.pool.acquire() as conn: rows = await conn.fetch( f"SELECT * FROM blacklists.{self.name} WHERE id = any($1::integer[]) ORDER BY id", indices) return [ BlacklistItem(row['id'], row['item'], row['retired']) for row in rows ]
async def get_all(self) -> List[BlacklistItem]: """Get all strings in the Blacklist.""" async with self.pool.acquire() as conn: rows = await conn.fetch( f"SELECT * FROM blacklists.{self.name} ORDER BY id") return [ BlacklistItem(row['id'], row['item'], row['retired']) for row in rows ]
async def add(self, item: str) -> Optional[BlacklistItem]: """Add a Chat to the DB or return an existing one. Args: item: The id of the chat Returns: The chat Document """ async with self.pool.acquire() as conn: row = await conn.fetchrow(f"INSERT INTO blacklists.{self.name} (item) VALUES ($1) RETURNING id", str(item)) return BlacklistItem(row['id'], item, False)
async def get_by_value(self, item: str) -> Optional[BlacklistItem]: async with self.pool.acquire() as conn: row = await conn.fetchrow(f"SELECT * FROM blacklists.{self.name} WHERE item = $1", str(item)) if row: if row['retired']: return None else: return BlacklistItem(row['id'], row['item'], row['retired']) else: return None