sget and sset
All checks were successful
Build Base Application / Build (push) Successful in 3m2s

This commit is contained in:
retoor 2024-12-14 21:25:52 +01:00
parent 361961cad4
commit 0cde635443

View File

@ -172,16 +172,24 @@ class WebDbApplication(BaseApplication):
return web.json_response(response)
async def set(self, key, value):
return self.sset(key,value)
def sset(self, key, value):
value = json.dumps(value, default=str)
return self.db["kv"].upsert({"key": key, "value": value}, ["key"])
async def get(self, key, default=None):
async def get(key,default=None):
return self.sget(key, default)
def sget(self, key, default=None):
record = self.db["kv"].find_one(key=key)
if record:
result = record.get("value", "null")
return result == "null" and default or json.loads(result)
return default
async def insert(self, table_name, data):
return self.db[table_name].insert(data)