javascript - NodeJS + mysql: Select query returning individual objects -


i have been using mysql npm package many months , have not faced issues. code acting strange.

 using(connectionpool.getsqlconnection(), function(connection) {         return connection.queryasync('select * table_name');     }).spread(function(rows, fields) {         console.log('rows: %j', rows);         console.log('fields: %j', fields);         res.json(rows);     }).error(function(err) {         console.log(err);     }); 

i know there 50 rows in table. getting 1 in rows. also, strangely fields has 2nd row. idea why happening? have used same query elsewhere no problems.

edit

i fiddled around little bit , found each row coming separate object. if change code following:

 using(connectionpool.getsqlconnection(), function(connection) {         return connection.queryasync('select * table_name');     }).spread(function(r1, r2, r3, r4) {         console.log('rows: %j', r1);         console.log('rows: %j', r2);         console.log('rows: %j', r3);         console.log('rows: %j', r4);         res.json(rows);     }).error(function(err) {         console.log(err);     }); 

each of r1, r2, r3, r4, ... have single row object.

answering myself helps else.

using(connectionpool.getsqlconnection(), function(connection) {         return connection.queryasync('select * table_name');     }).then(function(rows) {         console.log('rows: %j', rows);         res.json(rows);     }).error(function(err) {         console.log(err);     }); 

this works.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -