Node.js 如何将Mysql DB值获取到节点js中的json数组
如何将Mysql DB值获取到node js中的json数组中,谁能告诉我实现这一点所需的步骤吗?作为初学者,以下是您需要执行的步骤: 您需要将MySQL的依赖项添加到您的项目中,例如。 然后,您可以使用其select承诺访问行,如中所示。更清楚地说:Node.js 如何将Mysql DB值获取到节点js中的json数组,node.js,Node.js,如何将Mysql DB值获取到node js中的json数组中,谁能告诉我实现这一点所需的步骤吗?作为初学者,以下是您需要执行的步骤: 您需要将MySQL的依赖项添加到您的项目中,例如。 然后,您可以使用其select承诺访问行,如中所示。更清楚地说: return knex('books').select(knex.raw("data->'author' as author")) .whereRaw("data->'author'->>'first_name'=?
return knex('books').select(knex.raw("data->'author' as author"))
.whereRaw("data->'author'->>'first_name'=? ",[books[0].author.first_name])
.then(function(rows) {
// Here you have access to all rows as an array of objects
// which you can stringify
console.log("Found "+rows.length+
" books with authors first_name "+
books[0].author.first_name);
rows.forEach(function(row){
console.log(row);
});
})
你在使用哪些库?我是NodeJS的初学者。我只是想知道如何使用node js实现这一点,请与我分享实现这一点的步骤。你能具体告诉我在什么情况下我们使用web服务吗?我们是否使用web服务而不是从数据库填充网页数据?嗨,请就此提出另一个问题,以避免不相关的讨论污染这个问题。如果你对答案感到满意,请批准/投赞成票。