ejc-sql
ejc-sql copied to clipboard
Full query result export, e.g. as CSV
Quite often, when doing interactive analysis, I want to save all results into a file for later use, e.g. as CSV. This is similar to what you get in Oracle's SQL Developer when you right-click on the result browser and choose "Export".
I could not find this feature in EJC's documentation. I would also be happy to implement it and contribute it, if somebody gives me a bit of guidance how to start.
Hello, @JohannesFKnauf! That is pretty easy. The actual behavior of ejc-sql
is to print the result dataset to the file (in pain text table format). Then JVM notifies Emacs: "data printed into filepath
, please refresh the output buffer".
So, all you need is to provide your own ResultSet printer for any desired format like for plain text table here: https://github.com/kostafey/ejc-sql/blob/master/src/ejc_sql/output.clj#L182
Then, the actual output format can be customized as an optional parameter the same way as add-outside-borders
do:
- https://github.com/kostafey/ejc-sql/blob/master/ejc-sql.el#L755
- https://github.com/kostafey/ejc-sql/blob/master/src/ejc_sql/connect.clj#L280