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

async-mysql-query

v0.0.8

Published

Just writing mysql-sytax like sync-style in Node

Downloads

5

Readme

测试版本,尚不稳定

后续会加上 mysql按配置连接 为了测试 现在写死了!!!
直接通过传递配置项,生成实例,连接直接变成一个实例属性

Release Note

  version:0.0.2

  新增format和now实例方法
  新增cipher和hash实例方法
  version 0.0.2

  增加 raw_select(sql,arr)实例方法
  废弃 selectByParams 和 selectByPage实例方法

  新增直接生成带有连接的实例
  let conf1 ={
    host:your host,
    user:your username,
    password:your pwd,
    database:your chosed database
    ......
  }
  let db2 .....

  const db = new database(conf1)
  const db2 = new database(conf2)
  //此时db1 和 db2 为两个不同的连接,都具有自己的实例方法,独立进行不同数据库间的操作

  新增showPool和endPool实例方法,用于显示pool实例和关闭pool实例
  注意(3遍) 官方说endPool会等到队列结束才会平滑关闭 实测会立即关闭和destroy效果差不多
  官方原话:
  The end method takes an optional callback that you can use to know once all the connections have ended.   
  The connections end gracefully, so all pending queries will still complete and the time to end the pool will vary.  

  //建议像下面这样使用

  const db = new database(conf)

  async test_end(){
    let some = await db.somequery()
    //返回查询后再终结
    db.endPool()
    db.showPool()
  }

  test_end()

Install

npm install async-mysql-query

Introduction

引入

  const database = require('async-mysql-query')
  const db = new database()
  let obj = {
    id:'1234',
    hasGirlFriend:'yes',
    name:'joker'
  }
  //所有db实例的方法均会返回一个promise实例
  db.insert('user_info',obj)
  .then(t=>console.log(t))
  .catch(e=>console.log(e))

使用NodeJs8.0util.promisifyasync await 解决node-mysql模块的进行数据库操作时陷入callback hell

Async MySQL

insert

使用方法如下

//插入数据
db.raw_insert([arr])
usage:
    db.raw_insert(['user_info',['id','name','hasGirlFriend'],['1234','joker','yes']])
    .then(t=>console.log(t))
    .catch(err=>console.log(err))
execude as:
    let sql =
    `insert into user_info (id,name,hasGirlFriend) values ('1234','joker','1234')`

    pool.query(sql,(e,r)=>console.log(r))

db.insert(tableName,opt)
usage:
    let opt = {
      id:'1234',
      name:'joker',
      hasGirlFriend:'yes'
    }
    db.insert('user_info',opt)
    .then(t=>console.log(t))
    .catch(e=>console.log(e))

实例方法

方法 | 参数 | 说明 | --------------|--------|----------| db.raw_insert | arr | | db.insert | tableName,opt | |

select

db.selectByParams(sql,[arr])

usage:
    let sql =
    `select ?? from ?? where name = ? and hasGirlFriend = ? `
    let opt = [['id','name','age','hasGirlFriend'],'user_info','joker','nope']
    db.selectByParams(sql,opt)
    .then((t)=>console.log(t))
    .catch(e=>console.log(e))


db.selectByPages(sql,[arr])
//此方法可与上述方法合并

usage:
    let sql = `select ?? from ?? where name = ? and hasGirlFriend = ? limit ?,?`
    //此类分页方法扫描数据表时过慢  TODO  
    let opt = [['id','name','age','hasGirlFriend'],'user_info','joker','nope',0,5]
    db.selectByPages(sql,opt)
    .then(t=>console.log(t))
    .catch(e=>console.log(e))

db.countTable(tableName)

usage:

    db.countTable('user_info')
    .then(t=>console.log(t))
    .catch(e=>console.log(e))

实例方法

方法名 | 参数 | 说明 | ---------------------------|-------- |--------- | db.selectByParams | sql,opt | 废弃 | db.selectByPages | sql,opt |废弃 | db.raw_select(sql,arr) | sql,arr | 替代以上两方法 |
db.countTable | tableName | |

update

  db.update(arr)
  //arr = [tableName,obj,params]
  //适用一个过滤条件
  usage:
      let opt = {
        name:'joker',
        hasGirlFriend:'no'
      }
      let params = {
        id:'12345'
      }
      db.update('user_info',opt,params)
      .then(t=>console.log(t))
      .catch(e=>console.log(e))

  db.raw_update(sql,opt)
  //自定义更新语句 适用多个过滤条件的
  usage:
      let sql =
      `update ?? set ? where name = ? and hasGirlFriend = ?`
      let opt = {
        age:19,
        hasDream:'no'
      }
      let arr = ['user_info',opt,'joker','yes']
      db.update(sql,arr)
      .then(t=>console.log(t))
      .catch(e=>console.log(e))

delete


  db.delete(arr)
  usage:
      let arr = ["user_info",{name:'joker'}]
  execude as:
      sql = `delete from user_info where name = 'joker'`
      pool.query(sql,……)


  db.raw_delete(sql,arr)
  usage:
      let sql = `delete from ?? where name = ? and age = ? `
      let arr = ["user_info",'joker','22']
      db.delete(sql,arr)
      .then(t=>console.log(t))
      .catch(e=>console.log(e))