fix: 修复了一些bug并将剩余的同步代码改为异步执行

This commit is contained in:
RTAkland
2022-12-22 18:10:02 +08:00
parent ad055cf6fe
commit ce009e0203
6 files changed
+29 -24

No files matched your search

+7 -7
View File
@@ -24,30 +24,30 @@ class BaseSQL:
self.cursor.close()
self.conn.close()
def query(self, _id: str) -> tuple:
async def query(self, _id: str) -> tuple:
self.cursor.execute('select * from data where id="%s";' % _id)
result = self.cursor.fetchone()
if result is None:
self.insert(_id)
await self.insert(_id)
return tuple([_id, 0])
self.update(_id, result[1])
await self.update(_id, result[1])
return result
def insert(self, _id: str) -> bool:
async def insert(self, _id: str) -> bool:
self.cursor.execute('insert into data (id, times) values ("%s", 1);' % _id)
return True
def update(self, _id: str, times: int) -> bool:
async def update(self, _id: str, times: int) -> bool:
times += 1
self.cursor.execute('update data set times=%s where id="%s";' % (times, _id))
return True
def query_all(self) -> list:
async def query_all(self) -> list:
self.cursor.execute('select * from data;')
result = self.cursor.fetchall()
return result
def query_image(self, theme: str) -> list:
async def query_image(self, theme: str) -> list:
self.cursor.execute('select * from %s;' % theme)
result = self.cursor.fetchall()
return result