Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE - Allow running query as selection(s) from buffer, rather than writing entire buffer? Auto-folded results when multiple outputs? #30

Closed
CarbonChauvinist opened this issue May 7, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@CarbonChauvinist
Copy link

CarbonChauvinist commented May 7, 2020

Is it possible to have a mapping to execute the query, instead of writing the buffer? That way you could have many queries in a file and run them individually or only some but not all.

Originally posted by @moorecode in #8 (comment)

Following up on the comment above. Is this possible in any way? This would be a really useful feature.

I don't know if you've used cosminadrianpopescu's sql-workbench plugin (cosminadrianpopescu/vim-sql-workbench) which I know uses SQLWorkbench/J as its back-end and thus is different from what you may have available, but his does have this feature.

Another feature that the sql-workbench plugin has that would be amazing if it could be implemented here is it automatically autofolds query output in the results buffer when run with multiple queries, or for successive queries even. The current query is always expanded, but all previous results are autofolded.

It makes it really easy to navigate between result sets in the results buffer. (I've attached a screen grab which shows an example of this for reference.)
sqlworkbench_folded_result_sets

BTW yours is really an amazingly useful plugin! Thanks so much for creating and sharing, it is much appreciated.

@kristijanhusak kristijanhusak added the enhancement New feature or request label May 8, 2020
@kristijanhusak
Copy link
Owner

I added the folding, please give it a test. Executing selection requires a bit more work so it will be done eventually.

@kristijanhusak
Copy link
Owner

Support for executing the selection is added.
New mapping for sql buffer is introduced, <Leader>S. It works in both normal and visual mode. If executed from normal mode, executes whole buffer like write, and in visual mode executes only selection.
Give it a test and and let me know if it works.

@CarbonChauvinist
Copy link
Author

CarbonChauvinist commented May 8, 2020

Wow, this is amazing. Thanks for considering these requests and implementing them so quickly.

I've tested executing all in Normal mode and selections in Visual mode using <Leader>S and this works exactly as you detailed. This, to me, brings this very close to DBeaver for my use case and current needs. Thank you.

I also am really happy with the auto-folded results buffer as well. I do think maybe there's a slight offset in the folds though? I think you need to include an additional line instead of breaking at the blank line?

This picture shows three trivial queries run with the results all unfolded.
dbui_all_expanded

As you can see the result sets starts with the column names, then the returned rows, next a blank line, and then finally the number of rows affected/returned in parens.

However, when looking at the autofold results shown here the result sets stop at the blank line:
dbui_all_folded

Therefore the fold for the next result set is incorrectly showing the row count of the prior query and becomes confusing to navigate.

Fixing this may also make the folds more descriptive as they would be named the columns returned for the particular query?

(Ideally the folds would be named the query itself and also show the number of rows returned -- for instance brief mock-up of proposed fold below.):

+-- 6 lines: SELECT TOP 3 * FROM Supplier; (3 rows affected)----------------
+-- 5 lines: SELECT TOP 2 * FROM CustomerOrder; (2 rows affected)-----------

Thanks again for your time.

@kristijanhusak
Copy link
Owner

I've made folding according to output from postgres, which returns empty row betweeen the queries, and everything else has some content (no empty row between last table entry and count). Not sure how to tackle these different outputs between database types, but i'll try to figure something out.

@CarbonChauvinist
Copy link
Author

Understood, I was just thinking to myself that the query output ending with a blank line and then another line with the number of rows returned might be specific to mssql server and might not be consistent depending on the db one is using.

@kristijanhusak
Copy link
Owner

I just pushed a small change, but I don't have sqlserver db to test with currently. Can you pull and see if it works?

@CarbonChauvinist
Copy link
Author

Yes! Just tested and it works marvelously, thanks!
folds_fixed

@kristijanhusak
Copy link
Owner

Great! I just need to check mysql, it outputs things even more differently.

@kristijanhusak
Copy link
Owner

I set it up for mysql also, so it should be good to go. Closing.

@dgdosen
Copy link

dgdosen commented Jul 18, 2020

Is there a command for executing on the a single selection of sql that we can remap? I want to remap from Leader < S > to something else.

This is pretty great!

@kristijanhusak
Copy link
Owner

kristijanhusak commented Jul 18, 2020

@dgdosen

autocmd FileType sql nnoremap <your-mapping> <Plug>(DBUI_ExecuteQuery)

https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/doc/dadbod-ui.txt#L308

@dgdosen
Copy link

dgdosen commented Jul 19, 2020

Thanks - RTFM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants