bew / dotfiles

All my dotfiles in one place!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom simple & flexible UI over vim-dadbod

bew opened this issue · comments

See second comment for constructive info: #50 (comment)


The plugin https://github.com/kristijanhusak/vim-dadbod-ui is necessary (edit: it's not), but is a PAIN IN THE ASS TO USE!!!!

Because it forces you to use special buffers, that are managed by the plugin, not me!!!
The layout is rigid, and I cannot manage the windows myself without becoming crazy after a few window operations and query run..

Query buffers are meant to be run entirely by default, I never want to run the whole buffer (or I'll make a mapping for that if needed like :%RunTheQuery)
My mapping of choice to run the current query:
nmap <leader><leader> mmvip<Plug>(DBUI_ExecuteQuery)`m
basically:

  • save cursor position
  • visual select paragraph (aka the current sql query)
  • execute query
  • restore cursor position (it moved due to the paragraph visual selection)

The result buffer is very special ><, it seems you can have ONLY one, even if I have multiple query buffer opened.
It opens with <C-w>J
Running :CtrlSpace hides the result window ARGH!!! WHYY

There is no way to make a mapping to create a new query buffer. :/

The tree view of the tables, schemas does not show the column names, that would be highly useful though!
The only way to see them is to select the 'columns' entry in the tree view, that opens a pre populated query that I can run

Queries & DB connections are saved globally in my ~/
It should be per project (so saved locally! and reloaded from that dir/file when starting DBUI)

It's kinda hard / weird / unintuitive to open a sql file I saved somewhere (with :w my_file.sql), and link it to the DB I'm connected to with DBUI 'currently'. I can use :DBUIFindBuffer, but why?? why would I want to find the buffer in the list of special buffers for DBUI...

Actually I was wrong, some weird behavior of the result window is not from vim-dadbod-ui BUT from vim-dadbod plugin: https://github.com/tpope/vim-dadbod which is supposed to be minimal and flexible..

Using vim-dadbod without the other UI plugin

When using vim-dadbod without the UI from vim-dadbod-ui plugin, it is much better, and I have a better control on the windows, buffers, etc..

For example:

:e some_file.sql

# Set current DB for the buffer
:DB b:db = $INVENTORY_DATABASE_URI

# visual select a query, then run
:'<,'>DB b:db

# This show the special buffer with the result

I want my own flexible UI on top of vim-dadbod !!

I want to pin & name a result buffer

Currently the result buffer is volatile, simply running :CtrlSpace or running another query will hide the buffer.
Probably because of:
https://github.com/tpope/vim-dadbod/blob/779e8d6efc89b68be951ac1419baae75541cf51c/autoload/db.vim#L163
AND
https://github.com/tpope/vim-dadbod/blob/4a2a8bc6dca50bc58885bdf2c0a153d0990d7872/autoload/db.vim#L282
---> this last link tells us that the result window is a PREVIEW WINDOW!!! Instead it should be a proper window with configurable lifecycle!
---> That's why when I edit a query and do completion, the preview of the completion replaces the result window :/ too bad...
The result window should not be created (in an hardcoded way) by the plugin, it should be configurable, with a default value to pedit to open a preview window.

I want to be able to 'pin' a result buffer, so it does not disappear while I'm looking away, run :CtrlSpace, or run another query.
----> might need to change vim-dadbod? I could contribute to the plugin?

I want to give a 'virtual name' to a result buffer, without saving it to the file system when pinning, so I know what that result is about (e.g: "all resource types") (in vim's buffer list, in the status line, ...)

I want to see the result's input query in the result buffer

or have a mapping to show it / toggle it at the beginning of the result buffer.

I want to reload the result's buffer with the same query

vim-dadbod already has a mapping for that, but it doesn't seem to work...
The saved file for the query linked to a result buffer uses the interactive :DB<cr> command..

Suggestion:
In vim-dadbod, support b:some_var format for the query.
Then for a result buffer:

  • store the input query as a b:db_input_content variable
  • store the database used in a variable like b:db_uri
    Then to replay the query:
    :DB b:db_uri b:db_input_content

I want helper mappings, displays while writing queries

(ultimate would be to have some of these info in a floating window, but then how to position this window in non-obstrusive way?)

  • one to show the columns of a table (when I have the cursor on the (schema.)table name)
  • one to show the tables
  • one to create a new query buffer associated to the same db (or do I set g:db or t:db and use that always? I'd prefer no)

A discoverable tree view of the database would be helpful (similar to vim-dadbod-ui, but less rigid and simpler)

Another option: https://github.com/nanotee/sqls.nvim
This is a SQL language server ❤️ (https://github.com/lighttiger2505/sqls)

It supports executing sql commands through the language server..
The nvim layer is really simple, it should be easy to hack on!