node-mysql

Node MySQL execute multiple queries the fastest possible

一曲冷凌霜 提交于 2019-12-21 20:38:54
问题 Which is the fastest method gets the query to MYSQL, and then comes back to output: console.log('queries finished', results)" Is there an even better method? Please explain your answer! Thanks! Method 1: var connection = mysql.createConnection({multipleStatements: true}); connection.query('SELECT ?; SELECT ?', [1, 2], function(err, results) { if (err) throw err; console.log('queries done', results); }); Method 2: const Db = mysql.createPool({ connectionLimit: 7, dateStrings: true,

How to return a value from a mysql SELECT query in node.js

﹥>﹥吖頭↗ 提交于 2019-12-18 12:38:24
问题 I'm still very new to Node.js, and i'm trying to understand how callbacks work. So, here is my problem : I should've put more code : POST : app.post('/register', function(req, res) { //get data from the request var data = { username: req.body.username, email: req.body.email, password: req.body.password }; function fetchID(callback) { connection.query('SELECT id_user FROM USERS WHERE username = ?', data.username, function(err, rows) { if (err) { callback(err, null); } else callback(null, rows

Node.js cannot find module 'readable-stream'

て烟熏妆下的殇ゞ 提交于 2019-12-17 20:05:45
问题 I am new to node.js and stuck on the following. Any help will be appreciated: I am running node.js (0.10.28) on ubuntu (12.10). The code I am working on is: "use strict"; var mysql = require('node-mysql'), connection = mysql.createConnection({ host: "127.0.0.1", user: "user", password: "password", database: "dbname" }); if(connection) { console.log("Query"); connection.query("select * from client",function(err,res) { if(err)console.log(err); console.log(res); }); } I get the following error

How to properly pass mysql connection to routes with express.js

岁酱吖の 提交于 2019-12-17 15:30:43
问题 I am trying to figure out the best way to pass a mysql connection (using node-mysql) between my routes for express.js. I am dynamically adding each route (using a for each file loop in routes), meaning I can't just pass in the connection to routes that need it. I either need to pass it to every route or none at all. I didn't like the idea of passing it to ones that dont need it so I created a dbConnection.js that the routes can individually import if they need. The problem is that I dont

Not getting response for same query if executed more than 10 times in same script using node-mysql

∥☆過路亽.° 提交于 2019-12-13 15:18:50
问题 Few hours back I asked this question. I was troubleshooting it when I Zeroed in on this current issue. Here is the loop, if I execute the function selectPhotoById more than 10 times, I get response for only 10 queries. Example, for the following loop. for (var i = 0; i < 4; i++) { db.selectPhotoById("12246", function (res) { console.log(res[0].ID); }); } in the console response, I get 12246 12246 12246 12246 This works fine, but if i increase the loop like for (var i = 0; i < 24; i++) { db

Can't connect to localhost database from node.js server

久未见 提交于 2019-12-13 12:32:31
问题 Been having a lot of trouble trying to connect to to my localhost database. I've tried using the mysql and mysql-simple node modules but in both cases I just can't get it to connect. Here's what I used with the 'mysql' module: var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', port : '8000', user : 'uber', password : 'pass', }); connection.connect(function(err) { if (err) throw err; console.log('Connection Successful'); }); connection.query('USE someDB

Bulk insert mysql but from arrays of objects

人走茶凉 提交于 2019-12-13 06:50:01
问题 I've looked into this answer What I'm looking for is to be able to insert rows from a previous select query in nodejs and use the same RowDataPacket and pass it to another insert query. For instance, result from previous select call [ RowDataPacket { user_id: 1024, session_id: 3, notification_id: 1 }, RowDataPacket { user_id: 1028, session_id: 3, notification_id: 2 } ] ] following insert var sql = 'INSERT INTO user_session_notification(user_id, session_id, notification_id) VALUES ?' var

Node.js and mysql Callback : query in query callback

馋奶兔 提交于 2019-12-12 07:55:46
问题 All I want to do is insert some data if my database doesn't have that, so I put Insert SQL into my callback function of my Select SQL, but I got error like this: { [Error: Cannot enqueue Query after invoking quit.] code: 'PROTOCOL_ENQUEUE_AFTER_QUIT', fatal: false } my code snippet is here: db.query('SELECT count(*) as Resultcount FROM tablename WHERE email = ? and password = ?', [post.email, post.password], function(error, result){ if (result[0].Resultcount == 0){ var query2 = db.query(

Store mysql query rows in variable for later use

泄露秘密 提交于 2019-12-12 04:57:34
问题 I'm doing a monitoring system project in which I have Arduino sensors data being sent to a node.js server (thru GET requests) and then stored in a MySQL DB. Whenvever I successfully send data to the server, it connects to the MySQL DB and queries the last 5 received records to do some processing. Therefore, I need to store the rows of those 5 records in a variable for later use. Meaning that I have to get rows from a connection.query in a variable. I read that the fact that I'm not able to do

simple user login validation module with node

末鹿安然 提交于 2019-12-12 04:44:23
问题 I'm writing my first (non tutorial) node application and am at a point where I'm writing a function that should take the username and password as parameters and query them against the user table of my database to return either true or false. The database is setup, and the app is connecting to it successfully. However, I haven't worked with SQL very much, nor node, and I'm unsure how to proceed with this function (and short surrounding script). Here it is: console.log('validator module