pyrofork/pyrogram/storage/sqlite/sqlite.py
wulan17 fb5aff5e21
PyroFork: storage: sqlite: fix derps
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2023-06-27 17:02:13 +07:00

28 lines
959 B
Python

import sqlite3
from .cursor import AsyncCursor
from pathlib import Path
from pyrogram.utils import run_sync
from threading import Thread
from typing import Union
class AsyncSqlite(Thread):
def __init__(self, database: Union[str, Path], *args, **kwargs):
super().__init__()
self.connection = sqlite3.connect(database, *args, **kwargs)
async def commit(self):
return await run_sync(self.connection.commit)
async def close(self):
return await run_sync(self.connection.close)
async def execute(self, *args, **kwargs):
r = await run_sync(self.connection.execute, *args, **kwargs)
return AsyncCursor(r)
async def executemany(self, *args, **kwargs):
r = await run_sync(self.connection.executemany, *args, **kwargs)
return AsyncCursor(r)
async def executescript(self, *args, **kwargs):
r = await run_sync(self.connection.executescript, *args, **kwargs)