[英]How to get column name of data from RDS database as response in JSON in AWS Lambda Function using Nodejs
"records": [
[
{
"stringValue": "Smile Foundation2"
},
{
"stringValue": "Mumbai"
},
{
"stringValue": "+918600250073"
},
{
"stringValue": "Children"
},
{
"stringValue": "Alandi Pune ,411021"
},
So I get this response but the key name is the same for all I want it as different.所以我得到了这个响应,但是键名是相同的,因为我希望它不同。
You can use a simple select
query to fetch all the required field names
and their values
您可以使用简单的
select
查询来获取所有必需的field names
及其values
I am adding a Node.js
code below for reference that fetches data as JSON
in response from database using AWS Lambda Function
.我在下面添加了一个
Node.js
代码作为参考,该代码使用AWS Lambda Function
从数据库获取数据作为JSON
的响应。
var mysql = require ('mysql');
var pool = mysql.createPool
({
host : 'your RDS endpoint',
database : 'your database name',
user : 'your database username',
password : 'your database password',
});
exports.handler = (event, context, callback) =>
{
context.callbackWaitsForEmptyEventLoop = false;
pool.getConnection(function(error, connection)
{
connection.query ("SELECT column_name FROM table_name", function(error, results, fields)
{
connection.release();
if (error) callback(error);
else callback(null, JSON.stringify(results));
});
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.