mirror of
https://github.com/danbulant/sql2csv
synced 2026-06-17 05:21:27 +00:00
Better formating + sql2csv options
This commit is contained in:
parent
a4d43b6ddb
commit
b338bbbf84
1 changed files with 13 additions and 3 deletions
16
index.js
16
index.js
|
|
@ -4,6 +4,7 @@ const sql2csv = require("./sql2csv");
|
||||||
const configLoc = "config.yml";
|
const configLoc = "config.yml";
|
||||||
var config = {};
|
var config = {};
|
||||||
|
|
||||||
|
//logging functions for colored console. No support for windows cmd.exe (Use powershell!)
|
||||||
function log(str){
|
function log(str){
|
||||||
if(str == undefined){
|
if(str == undefined){
|
||||||
console.log();
|
console.log();
|
||||||
|
|
@ -24,14 +25,22 @@ function warn(str){
|
||||||
function error(str){
|
function error(str){
|
||||||
console.error("[ERROR] \x1b[41m" + str + "\x1b[0m");
|
console.error("[ERROR] \x1b[41m" + str + "\x1b[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Starting...");
|
log("Starting...");
|
||||||
var today = new Date();
|
var today = new Date();
|
||||||
var dateTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
var dateTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
||||||
log("Current time and date: " + dateTime);
|
log("Current time and date: " + dateTime);
|
||||||
log();
|
log();
|
||||||
//read and check config
|
|
||||||
|
const s2c = new sql2csv({
|
||||||
|
logging: true,
|
||||||
|
skipMysqlCheck: true
|
||||||
|
});
|
||||||
|
|
||||||
|
log();
|
||||||
|
//read config
|
||||||
var configFile = fs.readFileSync(configLoc);
|
var configFile = fs.readFileSync(configLoc);
|
||||||
if(Buffer.isBuffer(configFile)){
|
if(Buffer.isBuffer(configFile)){//converts to string if readFileSync returns buffer
|
||||||
configFile = configFile.toString();
|
configFile = configFile.toString();
|
||||||
}
|
}
|
||||||
configFile = configFile.split("\n");
|
configFile = configFile.split("\n");
|
||||||
|
|
@ -45,6 +54,7 @@ configFile.forEach((line) => {
|
||||||
if(value == parseInt(value)) value = parseInt(value);//save numbers as integers instead of strings
|
if(value == parseInt(value)) value = parseInt(value);//save numbers as integers instead of strings
|
||||||
config[line.substr(0, line.indexOf(":")).trim()] = value;
|
config[line.substr(0, line.indexOf(":")).trim()] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
//check config
|
//check config
|
||||||
if(config.showNames == undefined){
|
if(config.showNames == undefined){
|
||||||
warn("Undefined showNames, using false");
|
warn("Undefined showNames, using false");
|
||||||
|
|
@ -68,6 +78,6 @@ if(config.username == undefined){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.password == undefined){
|
if(config.password == undefined){
|
||||||
warn("Undefined password, using nothing");
|
warn("Undefined password, using (empty)");
|
||||||
config.password = "";
|
config.password = "";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue