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

mysql-easy-sql

v1.1.0

Published

see https://github.com/oppo12312312/mysql-easy-sql

Downloads

9

Readme

mysql-easy-sql

Json to SQL is much easier

example

const mysqlEasySql = require('mysql-easy-sql');

set database info

const informationSchema = app.mysql.createInstance(mysql.informationSchema);
const database = mysql.client.database;
const table = await informationSchema.query(` SELECT a.* FROM TABLES a where a.TABLE_SCHEMA = '${database}'`);
const column = await informationSchema.query(` SELECT a.* FROM COLUMNS a  WHERE a.TABLE_NAME in (SELECT a.TABLE_NAME   FROM TABLES a where a.TABLE_SCHEMA = '${database}')`);
mysqlEasySql.setDbInfoConfig({ table, column });

query

  const example = {
    // 必须传入字段
    tableName: 'teTest',
    //where 可以不传
    //where 传入的字段必须是tableName中存在的字段,否则报错提示
    //where 传入的sql关键字只能是 ['=','!=', '>', '>=', '<', '<=', 'between', 'not between', 'like', 'is' , 'in'],否则会报错
    where: {
      //时间格式: 请转化成2016-02-22 15:33:10,或则传入unit时间戳,不支持其他格式,如果传入其他时间格式,不会报错,会是查询结果错误
      dateTime: {
        // '>=': '2016-02-22 15:33:10', 
        // '<=': '2020-02-22 15:33:10', 
        // 'between': ['2016-02-22 15:33:10', '2020-02-22 15:33:10'], // between 和 not between 后面必须是一个length=2的数组, 否则会报错
        // 'not between': ['2010-02-22 15:33:10', '2011-02-22'] 
        '>=': 1298388790, 
        '<=': 1614007990, 
        'between': [1298388790, 1614007990], // between 和 not between 后面必须是一个length=2的数组, 否则会报错
        'not between': ['45', '23'] 
      },
      // in 有两种模式, 下面的是简写,也可以这样: enum: {in :[1, 11]}, 
      enum: [1, 11],  
      // text: {
      //   like: '%11%', //注意like 中的 %、_ 等通配符需要拼接到value中
      //   '=': '1121', 
      //   is: 'not null', // is 的值只能是 not null 和  null
      //   in: ['1121'] 
      // },
      // = 也有两种模式,下面的是简写,也可以这样:id: {"=" , 1}
      id: '1'
    },
    //columns 如果不传,则查询表中的所有字段,传入的字段必须是tableName中存在的字段,否则报错
    columns: ['enum', 'text', 'dateTime'],
    //orders 可以不传,传入的字段必须是tableName中存在的字段,否则报错
    orders: { id: 'desc' },
    //page 可以不传,必须是大于0的整数      
    pageNum: 1,
    pageSize: 10,
  };
mysqlEasySql.getSelectSqlByParam(example);
return 
SELECT a.`enum` AS enum, a.`text` AS text, unix_timestamp(a.`date_Time`) AS dateTime
FROM `Te_test` a
WHERE (a.`date_Time` >= from_unixtime(1298388790)
  AND a.`date_Time` <= from_unixtime(1614007990)
  AND a.`date_Time` BETWEEN from_unixtime(1298388790) AND from_unixtime(1614007990)
  AND a.`date_Time` NOT BETWEEN from_unixtime(45) AND from_unixtime(23)
  AND a.`enum` IN (1, 11)
  AND a.`id` = '1')
ORDER BY a.`id` DESC
LIMIT 0, 10

update

const example = {
    // 必须传入字段
    tableName: 'teTest',
    where: {
      id: '1'
    },
    //必传
    data: { text: '54444' }
};
mysqlEasySql.getUpdateSqlByParam(example);

return update `Te_test` a set a.`text` = '54444'  where a.`id` = '1' 

inset

const example = {
  // 必须传入字段
  tableName: 'teTest',
  data: { 
    id: '111', text: '54444', enum: 3, dateTime: 1298388790 
  }
};
mysqlEasySql.getInsetSqlByParam(example);

return 
insert into `Te_test` ( `id` ,`text` ,`enum` ,`date_Time` ) values ( '111','54444',3,from_unixtime(1298388790) )

delete

const example = {
    // 必须传入字段
    tableName: 'teTest',
    id: '85afc8b5-7e08-11e9-af95-0'
};
mysqlEasySql.getDeleteSqlByParam(example);

return 
delete from  `Te_test` where `id` = '85afc8b5-7e08-11e9-af95-0'