kostafey / ejc-sql

Emacs SQL client uses Clojure JDBC.
278 stars 29 forks source link

Full query result export, e.g. as CSV #144

Open JohannesFKnauf opened 3 years ago

JohannesFKnauf commented 3 years ago

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.

kostafey commented 3 years ago

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: