Last active
July 30, 2018 18:05
-
-
Save rskuipers/9210102ae01dfe17d833007ae5aa32b7 to your computer and use it in GitHub Desktop.
Custom extractor for PhpStorm to extract database tables as JSON
This file contains hidden or 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; } | |
function output() { for (var i = 0; i < arguments.length; i++) { OUT.append(arguments[i]); } } | |
var rows = []; | |
eachWithIdx(ROWS, function (row) { | |
var obj = {}; | |
eachWithIdx(COLUMNS, function (col) { | |
var value = FORMATTER.format(row, col); | |
if (value.toLowerCase() === "null") { | |
value = null; | |
} | |
try { | |
value = JSON.parse(value); | |
} catch (e) { } | |
obj[col.name()] = value; | |
}); | |
rows.push(obj); | |
}); | |
output(JSON.stringify(rows, null, 4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open a database table in PhpStorm, in the dropdown of formats to export as click on "Go to Scripts directory".
In "Extensions -> Database Tools and SQL -> data -> extractors" you can create a file called
JSON-JavaScript.json.js
and paste the above code in. Now you can extract the data as JSON.