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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pdtl

v1.0.4

Published

从数据库中提取项目数据并保存为JSON文件的命令行工具

Downloads

13

Readme

项目数据提取工具(project-data-tools)

这是一个从数据库中提取项目数据并保存为JSON文件的命令行工具。支持单个项目提取和批量提取功能。

功能特点

  • 支持从MySQL数据库中提取项目数据
  • 自动识别XML或JSON格式数据并正确处理
  • 支持单个项目、批量项目和范围查询三种操作模式
  • 支持获取最新记录功能
  • 文件名自动添加时间戳,便于区分不同版本
  • 提供详细的操作日志和统计信息
  • 支持通过命令行参数指定环境变量文件

安装和使用

方法一:通过NPM全局安装

# 全局安装
npm install -g pdtl

# 使用
pdtl <命令选项>

方法二:使用npx直接运行(无需安装)

npx pdtl <命令选项>

配置数据库连接

在使用前,您需要配置数据库连接信息。有三种方式:

  1. 创建.env文件
  2. 通过命令行参数--env-e指定环境变量文件路径
  3. 设置系统环境变量(适用于CI/CD环境或shell脚本)

方式一:使用默认.env文件

在工具同目录或当前工作目录下创建.env文件:

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_DATABASE=as_main
DB_PORT=3306

方式二:使用命令行参数指定环境变量文件

# 指定环境变量文件路径
pdtl --env ./config/production.env --latest

# 简写形式
pdtl -e ./config/production.env --latest

使用方法

# 全局选项(可与任何命令组合使用)
pdtl --env ./config/production.env <其他参数>

# 单个项目模式(获取指定项目的最新记录)
pdtl 12345

# 批量模式(获取多个项目的所有记录)
pdtl --batch 12345 12346 12347

# 范围模式(获取ID范围内的所有记录)
pdtl --range 12345 12350

# 最新全局模式(获取所有项目中最新的记录)
pdtl --latest     # 下载全局最新的1条记录
pdtl --latest 10  # 下载全局最新的10条记录

# 最新项目模式(获取指定项目的最新记录)
pdtl --latest-uid 12345      # 下载项目12345的最新记录
pdtl --latest-uid 12345 12346 12347  # 下载多个指定项目的最新记录

# 显示帮助
pdtl --help

输出结果

提取的数据将保存到data目录中,文件名格式为{PROJECT_UID}_{TIMESTAMP}.json。 时间戳格式为YYYY-MM-DD_HH-MM-SS,便于区分不同时间的数据版本。

常见问题

运行时找不到.env文件

确保.env文件与可执行文件在同一目录下,或者在当前工作目录下。

数据库连接问题

检查.env文件中的数据库配置是否正确,以及数据库服务器是否允许远程连接。