|
@@ -33,7 +33,9 @@ class DataStore(Generic[DataType]):
|
|
|
raise ValueError
|
|
|
self.datatype = datatype
|
|
|
self.connection = connection
|
|
|
- self.table_name = "".join(("_" + c.lower()) if "A" <= c <= "Z" else c for c in datatype.__name__).strip("_")
|
|
|
+ self.table_name = "".join(
|
|
|
+ ("_" + c.lower()) if "A" <= c <= "Z" else c for c in datatype.__name__ if c.isalnum()
|
|
|
+ ).strip("_")
|
|
|
|
|
|
async def setup(self):
|
|
|
await self.connection.execute(
|
|
@@ -45,7 +47,9 @@ class DataStore(Generic[DataType]):
|
|
|
await self.connection.commit()
|
|
|
|
|
|
async def load(self, key: str) -> Optional[DataType]:
|
|
|
- async with self.connection.execute(f"SELECT body FROM {self.table_name} WHERE key = ?", (key,)) as cursor:
|
|
|
+ async with self.connection.execute(
|
|
|
+ f"SELECT body FROM {self.table_name} WHERE key = ?", (key,)
|
|
|
+ ) as cursor:
|
|
|
found = await cursor.fetchone()
|
|
|
if found is None:
|
|
|
return found
|
|
@@ -69,7 +73,7 @@ class DataStore(Generic[DataType]):
|
|
|
await self.connection.execute(
|
|
|
f"INSERT INTO {self.table_name} VALUES (:key, :body) \
|
|
|
ON CONFLICT(key) DO UPDATE SET body=:body",
|
|
|
- { "key": key, "body": blob }
|
|
|
+ {"key": key, "body": blob},
|
|
|
)
|
|
|
await self.connection.commit()
|
|
|
|
|
@@ -100,4 +104,3 @@ class Data(InjectorWithCleanup[DataStore[DataType]]):
|
|
|
|
|
|
async def cleanup(self, store: DataStore[DataType]):
|
|
|
await store.connection.close()
|
|
|
-
|