Exemplo n.º 1
0
def get_dependent_resource(resource, primary_key, related_resource):

    #first retrieve the first primary key param
    resource_primary_key = dbaccess.get_primary_key(resource)
    query = []
    dic = dict()
    dic["column"] = resource_primary_key[0]
    dic["value"] = primary_key
    # list of size one of primary key mapping to value
    query.append(dic)

    #now retrieve and create the rest of the template
    args = request.args
    query_expression = dict(args)
    if "fields" in args.keys():
        field_expression = args['fields']
        del query_expression['fields']
    else:
        field_expression = None
    list_key_value = [[k, v] for k, v in query_expression.items()]

    for k, v in list_key_value:
        dic = dict()
        dic["column"] = k
        dic["value"] = v[0]
        query.append(dic)

    result = dbaccess.get_by_template(related_resource, field_expression,
                                      query)
    return result.to_json(orient='records')
Exemplo n.º 2
0
def delete_specific_resource(resource, primary_key):
    table_primary_key = dbaccess.get_primary_key(resource)

    query = []
    dic = dict()
    dic["column"] = table_primary_key[0]
    dic["value"] = primary_key
    query.append(dic)

    args = request.args

    if "fields" in args.keys():
        field_expression = args['fields']
    else:
        field_expression = None

    dbaccess.delete(resource, query)

    return "DELETE request sent."
Exemplo n.º 3
0
def get_specific_resource(resource, primary_key):
    table_primary_key = dbaccess.get_primary_key(resource)

    print(table_primary_key)
    query = []
    dic = dict()
    dic["column"] = table_primary_key[0]
    dic["value"] = primary_key
    query.append(dic)

    args = request.args

    if "fields" in args.keys():
        field_expression = args['fields']
    else:
        field_expression = None

    result = dbaccess.get_by_template(resource, field_expression, query)
    return result.to_json(orient='records')
Exemplo n.º 4
0
def add_dependent_resource(resource, primary_key, related_resource):

    #first retrieve the first primary key param
    resource_primary_key = dbaccess.get_primary_key(resource)
    query = []
    dic = dict()
    dic["column"] = resource_primary_key[0]
    dic["value"] = primary_key
    # list of size one of primary key mapping to value
    query.append(dic)

    #now retrieve and create the rest of the template
    result = dbaccess.get_by_template(resource, None, query)
    if len(result) != 0:
        if (request.is_json):
            new_resource = request.get_json()
            new_resource[resource_primary_key[0]] = primary_key
            dbaccess.insert(related_resource, new_resource)
            return "POST request completed."
    return "NOT FOUND", 404
Exemplo n.º 5
0
def put_specific_resource(resource, primary_key):
    table_primary_key = dbaccess.get_primary_key(resource)

    print(table_primary_key)
    query = []
    dic = dict()
    dic["column"] = table_primary_key[0]
    dic["value"] = primary_key
    query.append(dic)

    args = request.args

    if "fields" in args.keys():
        field_expression = args['fields']
    else:
        field_expression = None

    dbaccess.delete(resource, query)

    if (request.is_json):
        new_resource = request.get_json()
        dbaccess.insert(resource, new_resource)
    return "PUT request completed."