kocraft-backend/Craft/database/sqlite/data.py

34 lines
1.4 KiB
Python

from Craft.database.sqlite import Sqlite
from typing import Optional, List, Tuple
class SqliteDatabase:
@staticmethod
async def get(key1: str, key2: str) -> Optional[Tuple]:
async with Sqlite() as sqlite:
await sqlite.execute("SELECT * FROM Craft WHERE key1 = ? AND key2 = ?", (key1, key2))
data = await sqlite.fetchone()
return data
@staticmethod
async def sets(key1: str, key2: str, value_emoji: str, value_word: str) -> None:
async with Sqlite() as sqlite:
await sqlite.execute("INSERT INTO Craft (key1, key2, value_emoji, value_word, used_count) VALUES (?, ?, ?, ?, ?)", (key1, key2, value_emoji, value_word, 0))
@staticmethod
async def update(key1: str, key2: str) -> None:
async with Sqlite() as sqlite:
await sqlite.execute("UPDATE Craft SET used_count = used_count + 1 WHERE key1 = ? AND key2 = ?", (key1, key2))
@staticmethod
async def delete(key1: str, key2: str) -> None:
async with Sqlite() as sqlite:
await sqlite.execute("DELETE FROM Craft WHERE key1 = ? AND key2 = ?", (key1, key2))
@staticmethod
async def keys() -> List[Tuple]:
async with Sqlite() as sqlite:
await sqlite.execute("SELECT * FROM Craft")
data = await sqlite.fetchall()
return data