node.js - How to get Mysql DB values to a json array in node js -
how mysql db values json array in node js, can tell me steps follow achieve this
as you're beginner, here steps need perform:
- you need add dependency mysql project (e.g. knex js).
then, can use
select()
promise access rows in this gist. more clear:return knex('books').select(knex.raw("data->'author' author")) .whereraw("data->'author'->>'first_name'=? ",[books[0].author.first_name]) .then(function(rows) { // here have access rows array of objects // can stringify console.log("found "+rows.length+ " books authors first_name "+ books[0].author.first_name); rows.foreach(function(row){ console.log(row); }); })
Comments
Post a Comment