コード例 #1
0
def create_graphql_objects_with_list(my_cursor, mutations, method, db_dict,
                                     db_name, table_name, syn_dict, server):
    cols = db_dict[db_name][table_name]['col_order']
    query = ''
    for col in cols:
        if query != '':
            query += ','
        query += col
    query = 'SELECT ' + query + ' FROM ' + db_name + '.' + table_name
    my_cursor.execute(query)
    rows = my_cursor.fetchall()
    args = mutations[method]
    args_dict = {}
    for arg in args:
        add_arg_to_dict(arg, args_dict)
    counter = 0
    m = ''
    for row in rows:
        s = table_name + '_' + str(counter) + ': ' + method + '('
        counter += 1
        for i in range(len(cols)):
            col = cols[i]
            val = row[i]
            val_list = []
            if col == 'graph_id':
                col = 'id'
                graph_id = val
                if graph_id in syn_dict:
                    val_list = syn_dict[graph_id]
            if col in args_dict:
                arg = args_dict[col]
                if arg['is_boolean']:
                    val = str(val).lower()
                if arg['is_string']:
                    s += col + ': \\"' + str(val) + '\\", '
                else:
                    s += col + ': ' + str(val) + ', '
        s += 'list: ['
        for v in val_list:
            s += '\\"' + v + '\\",'
        s += ']'
        s += '),'
        m += s
        if (counter % 100 == 0):
            print(m)
            send_mutation(m, server)
            m = ''
    if m != '':
        print(m)
        send_mutation(m, server)
コード例 #2
0
def add_to_graphql_objects(my_cursor, mutations, method, db_dict, db_name,
                           table_name, server):
    args = mutations[method]
    args_dict = {}
    for arg in args:
        add_arg_to_dict(arg, args_dict)
    list_arg = get_list_arg(args_dict)
    obj_arg = get_obj_arg(args_dict)

    cols = db_dict[db_name][table_name]['col_order']
    query = ''
    for col in cols:
        field_info = db_dict[db_name][table_name][col]
        # item 3 is auto-incrmenet
        if field_info[3] == 'N':
            if col.lower().startswith(list_arg.lower()):
                query += col
    query += ', graph_id'
    query = 'SELECT ' + query + ' FROM ' + db_name + '.' + table_name
    counter = 0
    m = ''

    my_cursor.execute(query)
    rows = my_cursor.fetchall()
    for row in rows:
        adder_id = row[0]
        object_id = row[1]
        if adder_id != None:
            s = table_name + '_' + str(
                counter
            ) + ': ' + method + '(' + obj_arg + ': \\"' + object_id + '\\", ' + list_arg + ': [\\"' + adder_id + '\\"]), '
            m += s
        counter += 1
        if (counter % 100 == 0):
            print(m)
            send_mutation(m, server)
            m = ''
    if m != '':
        print(m)
        send_mutation(m, server)
コード例 #3
0
def add_list_to_graphql_objects(my_cursor, mutations, method, db_dict, db_name,
                                table_name, server):
    args = mutations[method]
    method_start = method
    if method_start.startswith('add'):
        method_start = method_start[3:]

    args_dict = {}
    for arg in args:
        add_arg_to_dict(arg, args_dict)
    list_arg = get_list_arg(args_dict)
    obj_arg = get_obj_arg(args_dict)

    cols = db_dict[db_name][table_name]['col_order']
    query = ''
    order_by = None
    object_id_index = 0
    added_id_index = 0
    i = 0
    for col in cols:
        field_info = db_dict[db_name][table_name][col]
        # item 3 is auto-incrmenet
        if field_info[3] == 'N':
            if query != '':
                query += ','
            query += col
            # col_head = get_col_head(col)
            if col.endswith('_graph_id'):
                object_name = col[:-9]
                if method_start.startswith(object_name):
                    object_id_index = i
                    order_by = col
                else:
                    added_id_index = i
            i += 1
    query = 'SELECT ' + query + ' FROM ' + db_name + '.' + table_name
    if order_by:
        query += ' ORDER BY ' + order_by
    my_cursor.execute(query)
    rows = my_cursor.fetchall()
    object_id = rows[0][object_id_index]
    counter = 0
    m = ''
    list_str = '['
    print(object_id)
    rows.append([0, 0])
    for row in rows:
        if row[object_id_index] != object_id:
            list_str += ']'
            s = table_name + '_' + str(
                counter
            ) + ': ' + method + '(' + obj_arg + ': \\"' + object_id + '\\", ' + list_arg + ': ' + list_str + '), '
            m += s
            counter += 1
            if (counter % 100 == 0):
                print(m)
                send_mutation(m, server)
                m = ''
            list_str = '['
            object_id = row[object_id_index]
        list_str += f'\\"{row[added_id_index]}\\",'