Created
December 23, 2017 13:45
-
-
Save dorukcan/cd59ae6239839cc40d0af1f3171b43fa to your computer and use it in GitHub Desktop.
intellij data extractor sqlite to mysql (for timestamps)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function eachWithIdx(iterable, f) { | |
var i = iterable.iterator(); | |
var idx = 0; | |
while (i.hasNext()) f(i.next(), idx++); | |
} | |
function mapEach(iterable, f) { | |
var vs = []; | |
eachWithIdx(iterable, function (i) { | |
vs.push(f(i)); | |
}); | |
return vs; | |
} | |
var SEPARATOR = "," | |
var QUOTE = "\"" | |
var NEWLINE = "\n"; | |
var q, str, dateArray, dateObject, tz_offset = 3; | |
var regex_timestamp = /(\d{4})-(\d{2})-(\d{2})\s?T?\s?(\d{2}):(\d{2}):(\d{2})/; | |
function outputRow(items) { | |
for (var i = 0; i < items.length; i++) { | |
str = items[i]; | |
// prettify value if it is a valid timestamp string | |
dateArray = regex_timestamp.exec(str); | |
if (dateArray) { | |
dateObject = new Date( | |
(+dateArray[1]), | |
(+dateArray[2]) - 1, // Careful, month starts at 0! | |
(+dateArray[3]), | |
(+dateArray[4]), | |
(+dateArray[5]), | |
(+dateArray[6]) | |
); | |
str = new Date(dateObject.getTime() + tz_offset * 3600000).toISOString().slice(0, 19).replace('T', ' '); | |
} | |
// output current string with | |
OUT.append(str) | |
.append(i != items.length - 1 ? SEPARATOR : NEWLINE); | |
} | |
} | |
if (TRANSPOSED) { | |
var values = mapEach(COLUMNS, function (col) { | |
return [col.name()]; | |
}); | |
eachWithIdx(ROWS, function (row) { | |
eachWithIdx(COLUMNS, function (col, i) { | |
values[i].push(FORMATTER.format(row, col)); | |
}); | |
}); | |
eachWithIdx(COLUMNS, function (_, i) { | |
outputRow(values[i], "td"); | |
}); | |
} | |
else { | |
outputRow(mapEach(COLUMNS, function (col) { | |
return col.name(); | |
})); | |
eachWithIdx(ROWS, function (row) { | |
outputRow(mapEach(COLUMNS, function (col) { | |
return FORMATTER.format(row, col); | |
})) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment