def write_data(db: dict, record_id: int, data_name: str, data):
    """Write data for a given record_id
    """
    if not db['db'].keys():
        db['db'][str(record_id)] = {}
    elif str(record_id) not in db['db']:
        db['db'][str(record_id)] = {}
    if not db['db'][str(record_id)].keys():
        db['db'][str(record_id)] = {data_name: data}
    elif db['writeback']:
        db['db'][str(record_id)][data_name] = data
    else:
        tmp_dict = db['db'][str(record_id)]
        tmp_dict[data_name] = data
        db['db'][str(record_id)] = tmp_dict
