visidata
visidata copied to clipboard
Added support to use visidata as mysql pager
Loader to use visidata in mysql (or mycli) client. Use the following config to enable visidata by default in the mysql client: Edit ~/.my.cnf: [mysql] silent pager=vd -f mysqlclient
- [X] If contributing a core loader, the loader checklist was referenced.
- [X] If registering an external plugin, the plugin checklist was referenced.
When using the mysql client, the output looks like this:
For large results this is quite unpleasant to work with. When configuring visidata as mysql pager the result of the query will be shown in visidata. Mysql has a builtin option to output data as TSV, so this loader could be used to parse the data from the client.
But the output is slightly different from a normal TSV:
- a newline (char(10)) is sent as the string \n (so one backslash and the character "n").
- a backslask is sent as the string \ (so 2 backslashes).
- a CR (char(13)) is sent literally, but interpreted by visidata as a row separator as universal newlines are by default enabled when opening files in text mode. this is why i added binary support to the Path class
- a tab is set as "t" (so one backslash and the character "t")
To view the real data (and not encoded data) i parse the data as a TSV in the newly written loader (with only \n as line separator, not \r) and i replace "\t" -> "\t", "\n" -> "\n", "\\" -> "\"
If you want i can split up this revision in 2. one for the core changes in the Path class, and one for the loader as an extension. I would personally not go for a separate extension as the mysql client (or mycli client) is used pretty commonly. A quick internet search also shows other people having the same problem: https://news.ycombinator.com/item?id=24774947
rebased to latest develop branch
i also dont like the copy past between the tsv and mysqlclient. i moved it to the tsv loader now as you asked and i added the extra options. the extra disable_universal_newline and interpret_escaped_chars options feel a bit forced for the tsv loader. what if we keep the mysqlclient loader but keep the code minimal by refering to the tsv loader? this way we dont have the options, en we also dont have the code copy paste
Hey @SuRaMoN, thanks for your patience. I've taken another look at this PR at last.
These seem to be the main areas of concern: text formats that aren't compatible with the universal newline, and parsing special characters for mysqlclient, and whether it's better to open stdin in binary instead of text mode.
I'm wondering, what if we added options.newline as a mechanism to set the newline character? Would that and options.encoding='unicode_escape' work for the mysqlclient use case? In that case, would we still need the ability to open the stdin as binary?
I think you are probably right about the open_text method in Path, it is kind of evil. This might be a good chance for us to clean that up. But if we can get away with the newline
option and a few minor changes, I'd like to do that first anyway.
If those do work for you, I would still like to merge the tests that are part of your PR, which will help us not regress this functionality in the future.
What I nice idea! :tada: I would love to see this feature being integrated :angel:
@SuRaMoN I am going to close this PR for now as inactive. If you ever want to pick it up again, we can re-open and have a fresh start.