From 73a9379a5062682ac0e10fef81109f4c79f84fcc Mon Sep 17 00:00:00 2001 From: Loong Date: Sun, 16 Jul 2023 16:07:45 +0800 Subject: [PATCH] Add saveDataBase --- easyNoSQL/system.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/easyNoSQL/system.py b/easyNoSQL/system.py index fe03de4..818de0e 100644 --- a/easyNoSQL/system.py +++ b/easyNoSQL/system.py @@ -47,6 +47,25 @@ def writeValue(keyName,valueName) -> bool: def changeSalt(newSalt) -> None: salt = newSalt + +def saveDataBase(filename,password='') -> bool: + noPassword = False + if password == '': + noPassword = True + if noPassword: + try: + with open(filename + '.json', 'w') as f: + f.write(json.dumps(t)) + except: + raise serror.KVDataBaseError(403,"An error occurred manipulating the database file.") + return True + d = json.dumps(t) + d = cryptos.encode(password + salt,d) + try: + with open(filename + '.json', 'w') as f: + f.write(d) + except: + raise serror.KVDataBaseError(403,"An error occurred manipulating the database file.") def version(): print('easyNoSQL - KV Database, Version: ' + easyNoSQL.system.VERTEXT)