如何在mysql中正确设置一个表,并在json数据的node.js中写入一个sql查询

我有一个node.js脚本将其数据保存到* .json文件。 我想转换这个保存到MySQL数据库的数据。 我已经尝试将表名设置为pendingPaymentList,并使用列名作为帐户,accountId,股票,并按types使用json,但一切都返回为[对象对象]或null。 我也尝试使用JSON.stringify和JSON.parse,但没有运气。

正如你所看到的,我不确定如何创build我的表和列以及编写一个sql查询来处理数据。 我希望表中的每一列都存储json数组中的每个不同的字段,以便我可以select它们并稍后显示每一列。 下面是保存的JSON数据的input,保存function和MySQL的查询。

/* example: { "pendingPaymentList": { "16021258545754610851": 2.17 } */ "pendingPaymentList": { "int": int }} 

保存function

 module.exports = { updateByNewBlock: updateByNewBlock, getStoredBalance: getStoredBalance, getPendingBalance: getPendingBalance, getBalance: getBalance, saveSession: saveSession, getAccountPending: getAccountPending, loadSession: function (done) { if (fs.existsSync('pool-payments.json')) { fs.readFile('pool-payments.json', function (err, data) { try { var loadedData = JSON.parse(data); if (loadedData.hasOwnProperty('blockPaymentList')) { blockPaymentList = loadedData.blockPaymentList; } if (loadedData.hasOwnProperty('pendingPaymentList')) { pendingPaymentList = loadedData.pendingPaymentList; } if (loadedData.hasOwnProperty('sentPaymentList')) { sentPaymentList = loadedData.sentPaymentList; if (sentPaymentList.length > poolConfig.maxRecentPaymentHistory) { var toRemove = sentPaymentList.length - poolConfig.maxRecentPaymentHistory; sentPaymentList.splice(0, toRemove); } 

和con info:

  var mysql = require('mysql'); var database = mysql.createConnection({ host: 'host', user: 'user', password: 'password', database: 'database' }); database.connect(function(connectionError){ if(connectionError){ throw connectionError; } var sql = "INSERT INTO pendingPaymentList(payments) VALUES ('" + JSON.parse(data) + "')"; database.query(sql, function(queryError, queryResult){ if(queryError){ throw queryError; } }); }); 

我真的只关心pendingPaymentList数组,直到我可以得到它正确地存储json数据并输出它,然后我将工作在blockPaymentList和sentPaymentList