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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mysqinfo

v1.2.8

Published

更加便捷的通过node使用mysql数据库,包含后端的基本操作函数

Downloads

115

Readme

安装

npm install mysqinfo

已经引入mysql工具包,无需在项目中再次引入mysql工具包

导入

const db = require('mysqinfo')

获取数据库对象

// db.dbconnect('mysql地址','mysql账号','mysql密码','数据库名字')
const mdb = db.dbconnect('127.0.0.1','root','123456','nodetest')

const sql = 'select 1'
mdb.query(sql,(err,res) => {
    if(err) return console.log(err.message);

    console.log(res);//[ RowDataPacket { '1': 1 } ]
})

查询数据

查询表中所有数据

//db.datafind(数据库对象,表名)
db.datafind(mdb, "users")
    .then((res) => {
        console.log(res);//查询结果
    })
    .catch((err) => {
        console.error(err);
    });

带过滤条件的查询

//db.datafindfilter(数据库对象,表名,查询条件)
db.datafindfilter(mdb,"users","id = 3")
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

删除数据

//db.datadeletefilter(数据库对象,表名,删除条件)
db.datadeletefilter(mdb,"users","id = 7")
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

添加数据

// db.dataadd(数据库对象,表名,添加数据对象)
db.dataadd(mdb,"users",{username:'test',password:'123456'})
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

修改数据

// db.dataupdate(数据库对象,表名,修改数据对象,过滤条件)
db.dataupdate(mdb,"users",{username:'updatesucess',password:'1111'},'id = 10')
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

模糊查询

查询包含此字段的所有数据

// db.datalikeinclude(数据库对象,数据表,模糊匹配对应字段名字,模糊查询匹配值)
db.datalikeinclude(mdb, "users","username","白")
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

查询包含此字段开头的所有数据

// db.datalikebegin(数据库对象,数据表,模糊匹配对应字段名字,模糊查询匹配值)
db.datalikebegin(mdb, "users","username","白")
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

连表查询

双表连接

// db.datadoubletablequery(数据库对象,表1,表2,表1连接字段,表2连接字段)
db.datadoubletablequery(mdb,"users","userscon1","id","userid")
    .then((res) => {
        console.log(res);
    })
    .catch((err) => {
        console.error(err);
    });

中间件

响应处理中间件

定义

//在所有路由之前使用
app.use(db.Responsemiddleware)

使用

//使用方法eg:
// 以查询所有数据为例子为例子
/*查询*/
db.datafind(mdb, "users")
    .then((res) => {
        console.log(res);
        /*可以调用res.cc来提示错误或者成功信息*/
        /**
         * res.cc(错误信息 错误对象or字符串,状态[默认为1代表错误,0代表成功])
         */
        res.cc("查询成功!",0)
    })
    .catch((err) => {
        console.error(err);
        /*可以调用res.cc来提示错误或者成功信息*/
        res.cc(err)
    });

错误中间件

//在所有路由之后使用
app.use(db.Responsemiddleware)
/*在请求中自动捕获错误,并且提前中断*/

开源协议

MIT