This commit is contained in:
parent
361961cad4
commit
0cde635443
@ -172,16 +172,24 @@ class WebDbApplication(BaseApplication):
|
|||||||
return web.json_response(response)
|
return web.json_response(response)
|
||||||
|
|
||||||
async def set(self, key, value):
|
async def set(self, key, value):
|
||||||
|
return self.sset(key,value)
|
||||||
|
|
||||||
|
def sset(self, key, value):
|
||||||
value = json.dumps(value, default=str)
|
value = json.dumps(value, default=str)
|
||||||
return self.db["kv"].upsert({"key": key, "value": value}, ["key"])
|
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)
|
record = self.db["kv"].find_one(key=key)
|
||||||
if record:
|
if record:
|
||||||
result = record.get("value", "null")
|
result = record.get("value", "null")
|
||||||
return result == "null" and default or json.loads(result)
|
return result == "null" and default or json.loads(result)
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def insert(self, table_name, data):
|
async def insert(self, table_name, data):
|
||||||
return self.db[table_name].insert(data)
|
return self.db[table_name].insert(data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user