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

csv2mysqlra

v1.3.1

Published

本工具是通过 sequlize 来将数据导入 mysql。当 csv 文件大小大于 100M 时,程序会使用,逐行读取方式来获取数据,以减少内存消耗。

Readme

csv 数据导入 mysql

本工具是通过 sequlize 来将数据导入 mysql。当 csv 文件大小大于 100M 时,程序会使用,逐行读取方式来获取数据,以减少内存消耗。

引入方式

npm i csv2mysqlra -S

使用方法

const csv2mysqlra = require('csv2mysqlra');

csv2mysqlra({
  seqConfig, // sequlize 配置
  csvDirPath: "./csv", // csv 数据所在目录
  modelDirPath: "./model", // sequlize model 定义未知
  batchNum: 600, // 每次批量导入数据的条数 默认 600
  workerNum: 6, // 启用的 worker 数量 默认 6 个
  logDirPath: "./log", // 异常日志目录
  startIndex: 0, // tbNames 起始位置 默认为0
  endIndex: 5, // tbNames 终止位置 默认为要导入表的数量
  tbNames: ["user"], // 表名 于 csv 文件名同名 如果不填,将默认csvDirPath下所有csv文件名为tbNames
  tbMaps:{ user:['user1.csv','user2.csv']}, // 新增功能,model 目录和 csv文件的映射假如 user 表有两份文件要导入,可以使用此功能。但是使用了tbMaps 那么 tbNames 就会失效。
  hasThRow: true, // csv 文件是否有表头行 默认为 true
  csvExtension: ".csv",// csv 文件后缀 默认为 .csv
  filter(tbName,row,ri){ // 数据过滤 需要导入的数据返回true 不需要的数据返回false
    // tbName 当前数据所在表的表名
    // row 当前读取行的字符串
    // ri 当前行所在行号 不含表头行
    return true|false;
  },
  headHandler(tbName, thRow) {
    // tbName 表名
    // thRow 表头所在行的字符串
    return 处理好后的字符串数组
  },
  rowHandler(thead, tbName, row, ri) {
    // thead 表头字符串数组
    // tbName 当前数据所在表的表名
    // row 当前读取行的字符串
    // ri 当前行所在行号 不含表头行
    return 处理好后的对象
  },
});

sequlize 配置

const seqConfig = {
  dialect: "mysql",
  host: "127.0.0.1",
  port: 3306,
  database: "db",
  username: "username",
  password: "password",
};

model 定义方式

module.exports = (sequelize, DataTypes) => {
  const { STRING, DATE, NOW } = DataTypes;

  const User = sequelize.define("users", {
    id: {
      field: "id",
      type: STRING(30),
      comment: "用户工号",
      primaryKey: true,
      unique: true,
    },
    name: {
      field: "name",
      type: STRING(255),
      comment: "用户姓名",
    },
    createdAt: {
      field: "created_at",
      type: DATE,
      comment: "创建时间",
      defaultValue: NOW,
    },
    updatedAt: {
      field: "updated_at",
      type: DATE,
      comment: "更新时间",
      defaultValue: NOW,
    },
  });
  return User;
};

约定

要导入的数据文件名与 model 文件名称必须保持一致。 比如在 model 目录中,定义了 user.js 文件,那么它定义的表所对应的 csv 文件必须是 user.csv

经过测试发现 worker = 6,batchNum = 600。导入速度最快。