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

yu-mysql

v2.0.1

Published

对mysql的进一步封装,减少代码量

Readme

安装

npm install yu-mysql

导入

const m = require('yu-mysql')

初始化数据库连接配置

// 数据库配置
const config = {   
    host: "your host",  //(必选)替换成你的host
    user: "root",   //(必选)替换成你的user
    password: "your password",  //(必选)替换成你的password
    database: "your database",  //(必选)替换成你的database
    port: 3306,   //(非必选)默认3306
    charset: "utf8mb4",  //(非必选)默认utf8mb4
    timezone: "+08:00"  //(非必选)默认+08:00
}
//m.init(config)需在首次调用数据库操作之前调用一次即可
//随后跨模块操作数据库可不再调用本方法
//建议在程序入口模块优先调用一次
m.init(config)

执行事务

const sqls = [
    "select * from table",
    "insert into table(name) values('yu')",
    "update table set name='yu'",
    "delete from table where id=1"
]
//update、insert、delete返回的是rows.affectedRows,select返回的是查询结果数组
//select 的时间数据将被格式化为'YYYY-MM-DD HH:mm:ss'
//返回值示例:retArr=[[{name: 'yu'}, {name: 'yu2'}], 1, 1, 0]
const retArr = await m.transaction(...sqls)

查询sql

const sql = "select * from table"
//返回值示例:ret=[{name: 'yu',telephone:'12345678910'}, {name: 'yu2',telephone:'12345678910'}]
const ret = await m.select(sql)
//返回值示例:ret=[{name: 'yu'}, {name: 'yu2'}]
const ret = await m.select(sql, ['telephone'])

插入sql

const datas=[
    {name: 'yu', telephone: '12345678910'},
    {name: 'yu2', telephone: '12345678910'}
]
//返回值示例:ret=1
const ret = await m.insert('tablename', ...datas)

更新sql

const datas=[
    {id: 1, name: 'yu', telephone: '12345678910'},
    {id: 2, name: 'yu2', telephone: '12345678910'}
]
//将id为1的name改为yu,telephone改为12345678910
//将id为2的name改为yu2,telephone改为12345678910
//返回值示例:ret=1
const ret = await m.update('tablename', 'id', ...datas)

删除sql

//删除id为1的数据
//返回值示例:ret=1
const ret = await m.delete('tablename', `id='1'`)