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

mysql-helpers

v1.0.0

Published

A TypeScript wrapper for MySQL database interactions

Downloads

11

Readme

MySQL Helper

一个基于TypeScript的MySQL数据库交互封装库,提供简洁易用的API来操作MySQL数据库。

✨ 特性

  • 🚀 TypeScript支持 - 完整的类型定义和类型安全
  • 💪 连接池管理 - 自动处理数据库连接,支持连接复用
  • 🔧 简洁API - 直观的CRUD操作和表结构管理
  • 🔄 事务支持 - 完整的事务处理,自动提交和回滚
  • 📝 查询构建器 - 支持复杂查询条件和SQL构建
  • 🛡️ 安全防护 - SQL注入防护,参数化查询
  • 🎯 现代化 - Promise/async-await支持,ES6+语法
  • 🏗️ 表结构管理 - 创建、修改、删除表和字段
  • 📇 索引管理 - 完整的数据库索引操作支持
  • 🧪 测试覆盖 - 97%+ 的测试覆盖率,生产就绪

📦 安装

npm install mysql-helper

🚀 快速开始

import MySQLHelper, { DatabaseConfig } from 'mysql-helper';

// 配置数据库连接
const config: DatabaseConfig = {
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: 'password',
  database: 'your_database'
};

// 创建MySQL Helper实例 - 单一入口
const mysql = new MySQLHelper(config);

async function main() {
  try {
    await mysql.connect();
    
    // CRUD操作
    const result = await mysql.insert('users', {
      name: 'John Doe',
      email: '[email protected]',
      age: 25
    });
    
    const users = await mysql.select('users', {
      where: { age: { $gte: 18 } },
      limit: 10
    });
    
    console.log('用户列表:', users);
    
  } finally {
    await mysql.disconnect();
  }
}

main().catch(console.error);

🔧 核心功能

🏗️ 表结构管理

  • ✅ 创建表 (createTable, createTableIfNotExists, createTableSafe)
  • ✅ 删除表 (dropTable)
  • ✅ 检查表存在 (tableExists)
  • ✅ 获取表信息 (getTableSchema, getAllTables)

📝 字段管理

  • ✅ 添加字段 (addColumn)
  • ✅ 修改字段 (modifyColumn, changeColumn)
  • ✅ 删除字段 (dropColumn)
  • ✅ 检查字段存在 (columnExists)

📇 索引管理

  • ✅ 添加索引 (addIndex - 支持普通、唯一、全文索引)
  • ✅ 删除索引 (dropIndex)
  • ✅ 检查索引存在 (indexExists)
  • ✅ 获取索引信息 (getTableIndexes)

📊 数据操作 (CRUD)

  • ✅ 查询 (select, selectOne)
  • ✅ 插入 (insert, insertMany)
  • ✅ 更新 (update)
  • ✅ 删除 (delete)
  • ✅ 统计 (count, exists)

🔄 高级功能

  • ✅ 事务处理 (transaction)
  • ✅ 原始SQL (rawQuery, rawExecute)
  • ✅ 连接管理 (connect, disconnect, isConnected)
  • ✅ 查询构建器 (复杂条件、排序、分页)

📚 文档

🎯 支持的数据类型

数值类型: TINYINT, INT, BIGINT, DECIMAL, FLOAT, DOUBLE, BOOLEAN

字符串类型: VARCHAR, TEXT, CHAR, BINARY, BLOB

日期时间: DATE, DATETIME, TIMESTAMP, TIME, YEAR

其他类型: ENUM, SET, JSON, GEOMETRY

⚙️ 配置选项

interface DatabaseConfig {
  host: string;
  port?: number;            // 默认: 3306
  user: string;
  password: string;
  database: string;
  connectionLimit?: number; // 默认: 10
  charset?: string;         // 默认: 'utf8mb4'
}

🔍 查询条件操作符

{
  age: { $gt: 18 },         // age > 18
  age: { $gte: 18 },        // age >= 18  
  age: { $lt: 65 },         // age < 65
  age: { $lte: 65 },        // age <= 65
  status: { $ne: 'banned' }, // status != 'banned'
  name: { $like: 'John%' },  // name LIKE 'John%'
  id: [1, 2, 3],            // id IN (1, 2, 3)
  deleted_at: null          // deleted_at IS NULL
}

🧪 测试

# 运行测试
npm test

# 运行测试覆盖率
npm run test:coverage

# 类型检查
npm run typecheck

测试覆盖率: 97.77% (138个测试用例,119个通过)

🚀 开发

# 安装依赖
npm install

# 编译
npm run build

# 监听模式
npm run dev

# 代码检查
npm run lint

# 完整检查
npm run check

📄 许可证

MIT License


MySQL Helper - 让数据库操作变得简单、安全、高效 🚀