Export data from tables in custom format with scripted extensions in JetBrains IDE

Recently i needed some data from database, and it must be in php-array format. I remember that phpMyAdmin could export data as php array, but i dont use it for a long time, because my phpstorm give enough instrument for manage project databases. I look in menu on database navigator,

So, it can export data as SQL insert/update, Html table, csv/tsv, json, xml… but seems php-array is not standard format for data transfer. As a last resort, we can convert json to a php array. At this time, my attention was drawn to the item called “Scripted Extensions”

The first two items did not look very clear, seems it java-specific. I choose “Go to Scripts Directory” and it open me in project panel

I’m not well familiar with groovy and closure script, but it also contain HTML-Javascript.html.js I opened this file, and it looked very much like what I needed.

I tried to find additional information in the official documentation of phpstorm and datagrip, https://www.jetbrains.com/help/datagrip/extending-the-product-functionality.html but it did not contain anything beyond what I already understood

So, I add new file in directory extractors with name PhpArrayExport.php.js and it appears in menu DumpDataToFile

After some experiments, i wrote script that make exactly what i want

Note: Es6 features not supported!

Result —

The next problem I encountered was that I could not export only selected rows in the table. I sent support request, with hope to get more detailed documentation about how to interact with selected rows. And they answered that it is impossible neither with custom extractors nor with the built-in ones. And also suggested to see “Open API” sources, that are located in %IDE_HOME%/lib/src/src_database-openapi.zip. for available methods . But i found more easy way —is make dump data from prepared sql query, or quick sql condition