def get(self): key = request.args.get('key') if key is None: return jsonify({"status": "error", "message": "key is required as a query param."}), 400 # Read data from the datasource with the key(data index). data_found, message = DataStoreCRD().check_read_data(key, self.db_path) if not data_found: return jsonify({"status": "error", "message": message}), 404 return jsonify(message), 200
def post(self): try: json_data = request.get_json(force=True) except Exception: return jsonify({"status": "error", "message": "Incorrect request data format. Only JSON object is acceptable."}), 400 # Create/Push data into the datasource. valid_data, message = DataStoreCRD().check_create_data(json_data, self.db_path) if not valid_data: return jsonify({"status": "error", "message": message}), 400 return jsonify({"status": "success", "message": message}), 200
def delete(self): key = request.args.get('key') if key is None: return jsonify({ "status": "error", "message": "key is required as a query param." }), 400 data_found, message = DataStoreCRD().check_delete_data( key, self.db_path) if not data_found: return jsonify({"status": "error", "message": message}), 404 return jsonify({"status": "success", "message": message}), 200
def delete(self): key = request.args.get('key') if key is None: return jsonify({ "status": "error", "message": "key is required as a query." }), 400 # Deletes a data from the datasource with the key(data index). data_found, message = DataStoreCRD().check_delete_data( key, self.db_path) if not data_found: return jsonify({"status": "error", "message": message}), 404 return jsonify({"status": "success", "message": message}), 200
"data1": "value1", "data2": "value2", "data3": "value3", "Time-To-Live": 5000, }, "def": { "data1": "value1", "data2": "value2", "data3": "value3", "Time-To-Live": 50, }, "ghi": { "data1": "value1", "data2": "value2", "data3": "value3", "data4": "value4", }, "jkl": { "data1": "value1", "data2": "value2", "data3": "value3", "Time-To-Live": 250, } } ################################ ''' CREATE DATA IN DATASTORE ''' _valid_data, message = DataStoreCRD().check_create_data(json_data, db_path) print(message) #################################
from configs import configurations from utils.filehandler import FilePreprocess from CRD.functions import DataStoreCRD # Adding/Enabling CommandLineArguments: --datastore parser = ArgumentParser() parser.add_argument('--datastore', help='Enter the datastore absolute path.') args = parser.parse_args() # Selecting the DataStore Directory. # Select user provided datastore path else, select the default path. if args.datastore: db_path = args.datastore else: db_path = configurations.DEFAULT_DB_PATH # Create a datastore directory. directory_created = FilePreprocess(db_path).create_folder() if not directory_created: print( f"Permission denied: You can not create the directory `{db_path}`.\n") exit(0) key = 'ghi' ################################ ''' READ DATA FROM DATASTORE ''' _data_found, message = DataStoreCRD().check_read_data(key, db_path) print(message) ################################
from argparse import ArgumentParser from configs import settings, configurations from utils.filehandler import FilePreprocess from CRD.functions import DataStoreCRD # Adding/Enabling CommandLineArguments: --datastore parser = ArgumentParser() parser.add_argument('--datastore', help='Enter the datastore absolute path.') args = parser.parse_args() # Selecting the DataStore Directory. # Select user provided datastore path else, select the default path. if args.datastore: db_path = args.datastore else: db_path = configurations.DEFAULT_DB_PATH # Create a datastore directory. directory_created = FilePreprocess(db_path).create_folder() if not directory_created: print( f"Permission denied: You can not create the directory `{db_path}`.\n") exit(0) key = 'ghi' ################################ '''DELETE DATA FROM DATASTORE''' _data_found, message = DataStoreCRD().check_delete_data(key, db_path) print(message) ################################