SQL文件处理工具

上传SQL文件
可以选择多个文件(按住Ctrl键多选)或选择ZIP压缩包
ZIP文件快速处理

直接上传ZIP文件并合并其中所有SQL文件:

ZIP一键处理
系统统计信息

查看API调用统计信息:

查看统计
功能说明

本工具提供两种处理模式:

  • 合并多个SQL文件:将多个SQL文件合并为一个文件
  • 处理单个SQL文件:解析单个SQL文件中的多条SQL语句,并标记整理
  • ZIP文件处理:提取ZIP文件中的所有SQL文件并合并
API接口详细说明
1. 文件上传 API

请求URL: POST /api/upload

功能说明: 上传一个或多个SQL文件,创建会话

请求参数:

  • files[]:文件数组,必须是SQL文件或ZIP文件

请求示例:

// 使用FormData发送
const formData = new FormData();
formData.append('files[]', file1);
formData.append('files[]', file2);

fetch('/api/upload', {
    method: 'POST',
    body: formData
})
.then(response => response.json())
.then(data => console.log(data));

成功响应:

{
    "success": true,
    "session_id": "20230401123456",
    "files": ["file1.sql", "file2.sql"]
}

错误响应:

{
    "error": "没有选择文件" 
}
// 状态码: 400
2. 文件处理 API

请求URL: POST /api/merge

功能说明: 处理已上传的SQL文件(合并多个文件或解析单个文件)

请求格式: JSON

请求参数:

  • session_id:会话ID,通过上传API获取(必填)
  • files:要处理的文件列表,不提供则处理所有文件(可选)
  • output_filename:输出文件名,默认为combined.sql(可选)
  • process_mode:处理模式,可选值:
    • merge:合并多个SQL文件(默认)
    • split:解析单个SQL文件中的多条语句

请求示例:

// 合并多个文件
fetch('/api/merge', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "session_id": "20230401123456",
        "files": ["file1.sql", "file2.sql"],
        "output_filename": "combined.sql",
        "process_mode": "merge"
    })
})
.then(response => response.json())
.then(data => console.log(data));

// 处理单个文件中的多条SQL语句
fetch('/api/merge', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "session_id": "20230401123456",
        "files": ["file1.sql"],
        "output_filename": "processed.sql",
        "process_mode": "split"
    })
})
.then(response => response.json())
.then(data => console.log(data));

成功响应:

{
    "success": true,
    "download_url": "http://yourserver.com/download/20230401123456/combined.sql"
}

错误响应:

// 会话ID无效
{
    "error": "无效的会话ID"
}
// 状态码: 404

// 处理模式错误
{
    "error": "无效的处理模式"
}
// 状态码: 400

// 处理单个文件时未选择文件或选择了多个文件
{
    "error": "请选择一个要处理的SQL文件"
}
// 状态码: 400
3. 文件下载 API

请求URL: GET /download/{session_id}/{filename}

功能说明: 下载处理后的SQL文件

URL参数:

  • session_id:会话ID
  • filename:文件名

示例:

// 直接在浏览器中打开下载链接
window.location.href = "http://yourserver.com/download/20230401123456/combined.sql";

// 或使用fetch下载
fetch("http://yourserver.com/download/20230401123456/combined.sql")
.then(response => response.blob())
.then(blob => {
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;
    a.download = 'combined.sql';
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
});
4. ZIP文件一键处理 API

请求URL: POST /api/process_zip

功能说明: 上传ZIP文件,提取并合并其中的所有SQL文件

请求参数:

  • file:ZIP文件(必填)
  • output_filename:输出文件名,默认为combined.sql(可选)

请求示例:

// 使用FormData发送
const formData = new FormData();
formData.append('file', zipFile);
formData.append('output_filename', 'all_combined.sql');

fetch('/api/process_zip', {
    method: 'POST',
    body: formData
})
.then(response => response.json())
.then(data => console.log(data));

成功响应:

{
    "success": true,
    "file_count": 5,
    "download_url": "http://yourserver.com/download/20230401123456/combined.sql"
}

错误响应:

// 没有选择文件
{
    "error": "没有选择文件"
}
// 状态码: 400

// 不是ZIP文件
{
    "error": "请上传ZIP文件"
}
// 状态码: 400

// ZIP中没有SQL文件
{
    "error": "ZIP文件中没有SQL文件"
}
// 状态码: 400
5. API调用统计信息 API

请求URL: GET /api/stats

功能说明: 获取API调用统计信息

请求示例:

fetch('/api/stats')
.then(response => response.json())
.then(data => console.log(data));

成功响应:

{
    "total": 58,
    "upload": 15,
    "merge": 20,
    "process_zip": 18,
    "download": 5,
    "timestamp": "2023-04-01 12:34:56"
}