douxun2018 2019-03-27 17:31
浏览 59

如何通过ajax将数百万行从DB导出到CSV?

I have million rows in my DB. I need to export all them into csv file. The problem is that i have timeout limit error.

So. I decided to do it via ajax.

I created ajax that generates me few tmp csv files

function chunkedExport()
{
    $.ajax({
        type: "POST",
        url: "transactions/",
        dataType: "JSON",
        data: $("#transactions").serialize(),
        async: false,
        success: function(response)
        {
            if (response.status === "continue")
            {
                $("#start_from").val(response.start_from);
                $("#client_file_name").val(response.client_file_name);
                $("#file_name").val(response.tmp_file_name);
                $("#step").val(response.step);
                chunkedExport();
            } else {
                console.log('DOWNLOAD');
                $("#start_from").val(0);
                $("#client_file_name").val('');
                $("#file_name").val('');
                $("#step").val(1);
                $("#export_type").val("");
                $('#csv_format').val("");

                document.location.href = '/transactions_export_csv/'+response.client_file_name+'/'+response.tmp_file_name+'/'+response.total_iterations+'/'
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            console.log([xhr, ajaxOptions, thrownError]);
            $("#start_from").val(0);
            $("#client_file_name").val('');
            $("#file_name").val('');
            $("#step").val(1);
            $("#export_type").val("");
            $('#csv_format').val("");
        }
    });
}

the question is how to combine them all into one csv file and download it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置