示例#1
0
class DbTestCase(unittest.TestCase):
    def test_connection(self):
        self.db = DB(DB_PATH)
        self.assertIsNotNone(self.db, msg='Impossible to create db "test_db"')
        self.assertIsNotNone(self.db.get_con(),
                             msg='Impossible to connect to db "test_db"')
        self.db.close()
        self.assertIsNone(self.db.conn,
                          msg='Impossible to disconnect to db "test_db"')
 async def set(self, guild, value):
     self.__data[guild.id] = value
     lock = asyncio.Lock()
     async with lock:
         db = DB()
         query = f"""
         INSERT INTO {self.table} (guild_id, value)
           VALUES (?, ?)
           ON CONFLICT (guild_id)
           DO UPDATE SET value=?;
         """
         db.cursor.execute(query, (guild.id, value, value))
         db.commit()
         db.close()
 def load(self):
     db = DB()
     result = db.cursor.execute(f'SELECT * FROM `{self.table}`;')
     self.__data = {guild_id: value for guild_id, value in result.fetchall()}
     db.close()