npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

n8n-nodes-database-importer

v1.0.9

Published

An n8n node to import data from Kingsoft WPS output to MySQL database with field mapping and deduplication

Downloads

905

Readme

n8n Database Importer Node

一个用于将Kingsoft WPS工作流节点输出的数据导入到MySQL数据库的n8n自定义节点。

功能特性

1. 数据库连接配置

  • Host: MySQL服务器地址
  • Port: MySQL端口 (默认: 3306)
  • Database: 数据库名称
  • User: 数据库用户名
  • Password: 数据库密码
  • Connect Timeout: 连接超时时间 (毫秒,默认: 10000)
  • Connection Pool Limit: 连接池最大连接数 (默认: 10)

2. 导入模式

全量导入 (Full Import)

  • 先清空目标表(可选)
  • 将所有数据导入目标表
  • 适用于完全替换表数据的场景

增量导入 (Incremental Import)

  • 根据唯一键组合进行去重过滤
  • 只导入不存在的新数据
  • 支持单个或多个字段组成的唯一键
  • 适用于追加新数据的场景

3. 分批导入

  • 支持自定义批次大小
  • 默认每批处理 5000 条记录
  • 范围: 100-10000 条/批
  • 提高大数据量导入的性能和稳定性

4. 字段映射

  • 支持源字段到目标字段的灵活映射
  • 可添加多个字段映射
  • 源字段名: Kingsoft节点输出的字段名
  • 目标字段名: 数据库表中的字段名

5. 导入数量验证

  • 自动验证导入数量是否一致
  • 比对源数据行数与实际导入行数
  • 提供详细的导入统计信息

安装

方式1: 从npm安装 (发布后)

npm install n8n-nodes-database-importer

方式2: 手动安装

  1. 克隆或下载此项目
  2. 在项目目录下运行:
npm install
npm run build
  1. 将生成的 dist 目录链接到n8n的自定义节点目录

方式3: 在n8n中直接安装

  1. 打开n8n设置
  2. 进入 "Community Nodes"
  3. 搜索 "n8n-nodes-database-importer"
  4. 点击安装

使用说明

1. 配置数据库凭据

  1. 在n8n中创建新的凭据
  2. 选择 "MySQL Database"
  3. 填写数据库连接信息:
    • Host: 数据库服务器地址
    • Port: 端口号 (默认3306)
    • Database: 数据库名
    • User: 用户名
    • Password: 密码
    • Connect Timeout: 连接超时时间(可选)
    • Connection Pool Limit: 连接池大小(可选)

2. 添加Database Importer节点

  1. 在工作流中添加 "Database Importer" 节点
  2. 连接到Kingsoft节点输出
  3. 选择已配置的MySQL凭据

3. 配置导入参数

基础配置

  • Import Mode: 选择导入模式 (Full/Incremental)
  • Target Table: 目标数据库表名
  • Batch Size: 批次大小 (默认5000)

字段映射

点击 "Add Field Mapping" 添加字段映射:

  • Source Field: Kingsoft输出的字段名 (如: "快手ID")
  • Target Field: 数据库表字段名 (如: "kuaishou_id")

示例:

Source Field: 快手ID       → Target Field: kuaishou_id
Source Field: 快手昵称     → Target Field: nickname
Source Field: 集团号       → Target Field: group_number
Source Field: 所属端口     → Target Field: port

增量导入配置

如果选择增量导入模式:

  • Unique Key Fields: 填写唯一键字段 (多个字段用逗号分隔)
    • 示例: kuaishou_id (单字段)
    • 示例: kuaishou_id,nickname (多字段组合)

高级选项

  • Truncate Table Before Import: 全量导入前是否清空表 (默认: true)
  • Continue on Error: 遇到错误是否继续处理 (默认: false)
  • Verify Import Count: 是否验证导入数量 (默认: true)

4. 运行工作流

执行工作流后,节点将输出导入结果:

{
  "success": true,
  "totalRows": 9070,
  "importedRows": 9070,
  "duplicateRows": 0,
  "failedRows": 0,
  "message": "Successfully imported 9070 rows (0 duplicates, 0 failed)"
}

工作流示例

示例1: 全量导入

Kingsoft节点 → Database Importer节点

配置:

  • Import Mode: Full Import
  • Target Table: kuaishou_accounts
  • Truncate Table: Yes
  • Field Mappings:
    • 快手ID → kuaishou_id
    • 快手昵称 → nickname
    • 集团号 → group_number

示例2: 增量导入

Kingsoft节点 → Database Importer节点

配置:

  • Import Mode: Incremental Import
  • Target Table: kuaishou_accounts
  • Unique Key Fields: kuaishou_id
  • Field Mappings:
    • 快手ID → kuaishou_id
    • 快手昵称 → nickname
    • 开户日期 → account_date

输入数据格式

节点接受Kingsoft节点的输出格式:

[
  {
    "data": {
      "result": [
        ["快手ID", "快手昵称", "集团号", "所属端口"],
        [1469773427, "问美美妆", "", "上海亦盟"],
        [2426532761, "黄皮肤旗舰店", "", "上海亦盟"]
      ]
    },
    "status": "finished"
  }
]

第一行为表头(字段名),后续行为数据行。

输出数据格式

节点输出导入结果统计:

{
  "success": true,
  "totalRows": 100,
  "importedRows": 95,
  "duplicateRows": 5,
  "failedRows": 0,
  "message": "Successfully imported 95 rows (5 duplicates, 0 failed)"
}

字段说明:

  • success: 导入是否成功
  • totalRows: 源数据总行数
  • importedRows: 成功导入的行数
  • duplicateRows: 重复跳过的行数 (增量导入)
  • failedRows: 失败的行数
  • message: 导入结果消息

注意事项

  1. 数据库权限: 确保数据库用户有目标表的INSERT、SELECT、TRUNCATE权限
  2. 字段类型: 确保源数据类型与目标字段类型兼容
  3. 唯一键: 增量导入时,确保目标表上有对应的唯一索引或主键
  4. 批次大小: 根据数据量和服务器性能调整批次大小
  5. 事务处理: 每批数据在事务中处理,失败会自动回滚
  6. 性能优化: 大数据量导入建议使用较大的批次大小(如5000-10000)

故障排查

问题1: 连接超时

  • 检查数据库服务器是否可访问
  • 增加 Connect Timeout 值
  • 检查防火墙设置

问题2: 导入失败

  • 检查字段映射是否正确
  • 检查数据类型是否匹配
  • 查看错误日志获取详细信息
  • 启用 "Continue on Error" 继续处理其他批次

问题3: 重复数据未去重

  • 确保目标表有唯一索引
  • 检查 Unique Key Fields 配置是否正确
  • 验证字段映射中包含了唯一键字段

问题4: 性能慢

  • 增加批次大小
  • 增加连接池大小
  • 检查数据库索引配置
  • 考虑在非高峰期执行

开发

构建

npm run build

开发模式(监听文件变化)

npm run dev

代码格式化

npm run format

代码检查

npm run lint
npm run lintfix  # 自动修复

技术栈

  • TypeScript
  • n8n-workflow
  • n8n-core
  • mysql2 (Promise API)

许可证

MIT

支持

如有问题或建议,请提交Issue或Pull Request。

更新日志

v1.0.0 (2024-11-19)

  • 初始版本发布
  • 支持全量/增量导入
  • 支持字段映射
  • 支持分批导入
  • 支持导入数量验证
  • 支持连接池配置