Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commonly used query commands for nodejs Sequelize and mysql

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Here are some common query commands about nodejs Sequelize and mysql. The secret of the text is that it is close to the topic. So, no gossip, let's go straight to the following, I believe that after reading nodejs Sequelize and mysql what commonly used query commands this article will certainly benefit you.

# remove unionid duplicate search results # query_resultsign table name select *, count (unionid) from query_resultsign where issign='false' group by unionid; # remove unionid duplicate search results # query_resultsign table name select *, count (unionid) from query_resultsign where issign='true' group by unionid # find the average access frequency of unsigned users (that is, the average of the search results column issign='false' is not signed) # cuid is the alias of unid # query_resultsign table name select AVG (bs.cuid) as unUserAvg FROM (select *, count (unionid) cuid from query_resultsign where issign='false' group by unionid) as bs # find the average # (that is, the average of the issign='true' count of the search results) # bs is the alias of the subquery. If you don't have an alias, you will report an error # query_resultsign table name select AVG (bs.cuid) userAvg FROM (select *, count (unionid) cuid from query_resultsign where issign='true' group by unionid) as bs;# add id column int # query_resultsignALTER TABLE query_resultsign add id int # change the columns added to the table query_resultsign (previous step) into self-increasing columns alter table query_resultsign change id id int NOT NULL AUTO_INCREMENT primary key; # get the columns with the same data in the two columns of data # query_resultsign table name select p1.* from query_resultsign p1 where p1.idp2.id and p2 where p1.idp2.id and p1.x = p2.x and p1.y = p2.y # users with the same look-up table query_resultsign unionid select p1.* from query_resultsign p1Query from query_resultsign resultsign p2 where p1.idp2.id and p1.unionid = p2.unionid

Sequelize's method of calling SQL statements by the way, most of the tutorials on the Internet are queried by model, and model is set up every time. It's a little troublesome. For a tutorial on configuration, see the configuration tutorial.

Sequelize mainly uses the query (sql, {}) method to call sql:

Var Sequelize = require ('sequelize'); / introduce sequelize var sequelize = require ('. /.. /.. / database/dataconfig'); / / introduce connection profile / / find subscriber exports.selectHeatData = function (req, res) {return sequelize.query ("select * from `query_ resultSign` where issign = 'true'", {type: sequelize.QueryTypes.SELECT}) .then (data = > {/ / console.log (' *', data) Res.send (data);}) .catch (err = > {console.log ('error', err)})} / / the other way is to change the sql statement

The main knowledge point is the type {type: sequelize.QueryTypes.SELECT} of the query result passed in the query method so that it doesn't have to be manually converted to a json object.

Comes with profile code

Dataconfig.js

Var Sequelize = require ('sequelize') Module.exports = new Sequelize ('database name', 'user name', 'login password', {host: 'localhost', / / database address dialect:' mysql', / / specify the database type of connection operatorsAliases: false, pool: {max: 5, / / maximum number of connections in the connection pool min: 0 / / minimum number of connections in the connection pool idle: 10000 / / if a thread has not been used in 10 seconds Then release the thread}

});

Are there any common query commands related to the above nodejs Sequelize and mysql that you don't understand? Or if you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report