Minor Syntax improvements
- Replaced convertDateToString() to new Date() as SQL queries accepts js-object Date - Pass nested array for bulk insert in backup-restore
This commit is contained in:
parent
a193291bd7
commit
5344b79cdb
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
/args/param.json
|
||||
/args/keys*.json
|
||||
*test*
|
||||
*.tmp*
|
||||
|
||||
@ -319,16 +319,15 @@ function updateTableData(table, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!data.length)
|
||||
return resolve(null);
|
||||
let cols = Object.keys(data[0]),
|
||||
_mark = "(" + Array(cols.length).fill('?') + ")";
|
||||
let values = data.map(r => cols.map(c => validateValue(r[c]))).flat();
|
||||
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)}` +
|
||||
let cols = Object.keys(data[0]);
|
||||
let values = data.map(r => cols.map(c => validateValue(r[c])));
|
||||
let statement = `INSERT INTO ${table} (${cols}) VALUES ?` +
|
||||
" ON DUPLICATE KEY UPDATE " + cols.map(c => `${c}=VALUES(${c})`).join();
|
||||
DB.query(statement, values).then(_ => resolve(true)).catch(error => reject(error));
|
||||
DB.query(statement, [values]).then(_ => resolve(true)).catch(error => reject(error));
|
||||
})
|
||||
}
|
||||
|
||||
const validateValue = val => (typeof val === "string" && /\.\d{3}Z$/.test(val)) ? global.convertDateToString(val) : val;
|
||||
const validateValue = val => (typeof val === "string" && /\.\d{3}Z$/.test(val)) ? new Date(val) : val;
|
||||
|
||||
function verifyChecksum(checksum_ref) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@ -195,7 +195,7 @@ function processOrders(seller_best, buyer_best, asset, cur_rate, quantity) {
|
||||
}));
|
||||
txQueries.push([
|
||||
"INSERT INTO TradeTransactions (seller, buyer, asset, quantity, unitValue, tx_time, txid) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
[seller_best.floID, buyer_best.floID, asset, quantity, cur_rate, global.convertDateToString(time), hash]
|
||||
[seller_best.floID, buyer_best.floID, asset, quantity, cur_rate, new Date(time), hash]
|
||||
]);
|
||||
|
||||
return txQueries;
|
||||
|
||||
@ -325,7 +325,7 @@ function transferToken(sender, receivers, token) {
|
||||
}));
|
||||
txQueries.push([
|
||||
"INSERT INTO TransferTransactions (sender, receiver, token, totalAmount, tx_time, txid) VALUE (?, ?, ?, ?, ?, ?)",
|
||||
[sender, JSON.stringify(receivers), token, totalAmount, global.convertDateToString(time), hash]
|
||||
[sender, JSON.stringify(receivers), token, totalAmount, new Date(time), hash]
|
||||
]);
|
||||
DB.transaction(txQueries)
|
||||
.then(result => resolve(hash))
|
||||
|
||||
@ -2,16 +2,6 @@
|
||||
//fetch for node js (used in floBlockchainAPI.js)
|
||||
global.fetch = require("node-fetch");
|
||||
|
||||
global.convertDateToString = function(timestamp) {
|
||||
let date = new Date(timestamp);
|
||||
return date.getFullYear() + '-' +
|
||||
('00' + (date.getMonth() + 1)).slice(-2) + '-' +
|
||||
('00' + date.getDate()).slice(-2) + ' ' +
|
||||
('00' + date.getHours()).slice(-2) + ':' +
|
||||
('00' + date.getMinutes()).slice(-2) + ':' +
|
||||
('00' + date.getSeconds()).slice(-2);
|
||||
}
|
||||
|
||||
//Set browser paramaters from param.json (or param-default.json)
|
||||
var param;
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user