const utils = require('.');
const {
stringify
} = require('csv-stringify');
module.exports = {
import_data: async function() {
// TODO:
},
export_data: async function() {
const tables = await utils.query("SHOW TABLES");
const csv_rows = await Promise.all(tables.filter(function(table) {
return !["sessions"].includes(table)
}).map(async function(table) {
console.log(table);
const rows = await utils.query("SELECT * FROM " + table["Tables_in_budget"]);
if (!rows.length) {
return;
}
let [first_row, ...rest_rows] = [rows.unshift(), ...rows];
delete first_row.id;
return [Object.keys(first_row), ...[first_row, ...rest_rows].map(function(row) {
delete row.id;
return Object.values(row);
})];
}));
return stringify(csv_rows, {
header: true
});
}
};