-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add option for setting g:db from the menu #54
Comments
There's already a command that allows you to partially use this. This is not working for non sql filetypes, because dbui converts it to sql filetype. I plan to improve that. |
I did the improvement. Now you can assign any filetype to dbui with
If you can give it a test and let me know how it looks. |
Unless there is something I'm missing dbui can only execute the entire content of the dbui buffer. This doesn't work very well for inline SQL, because most of the buffer is not SQL. Say I have this pseudo-C: void main() {
run_sql(con, "SELECT * FROM foo;");
} If I turn this buffer to a dbui buffer with |
You have a mapping for executing visual selection (https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/doc/dadbod-ui.txt#L315), and by default it's mapped to augroup dbui_custom
autocmd!
autocmd FileType cpp vnoremap <buffer><silent><Leader>S <Plug>(DBUI_ExecuteQuery)
augroup END
" Do not execute whole buffer on save
let g:db_ui_execute_on_save = 0 With this, you do |
Doesn't work... Anyway, I managed to hack it it with this script: function! s:getDbuiScriptNumber() abort
" Make sure it's loaded:
call db_ui#get_conn_info('')
for l:line in split(execute('scriptnames'), '\n')
if l:line =~ '\vautoload/db_ui.vim$'
return str2nr(split(l:line, ':')[0])
endif
endfor
endfunction
function! s:getDbuiInstance() abort
return function(printf('<SNR>%d_init', s:getDbuiScriptNumber()))()
endfunction
function! s:chooseDbuiConnection() abort
let l:keys = keys(s:getDbuiInstance().dbs)
call fzf#run({
\ 'source': l:keys,
\ 'sink': function('s:setDbConnection'),
\ 'down': '~40%',
\ })
endfunction
function! s:setDbConnection(key) abort
let b:db = s:getDbuiInstance().dbs[a:key].url
endfunction
command! DBUISetDbConnection call s:chooseDbuiConnection() |
Which part doesn't work? |
I made a mistake in my comment, it shouldn't be autocmd FileType cpp vmap <buffer><silent><Leader>S <Plug>(DBUI_ExecuteQuery) I see that you are doing this nasty script id parsing to get all available connections. Do you want to get list of available connections in format |
The mapping doesn't work. I see At any rate I'd still prefer to set |
That's odd. Does it work if you try to execute visual selection in dbui sql buffer? I added |
Weird - I tried the mapping again after updating the plugin, and it worked... Anyway |
Sometimes it's useful to run SQL commands from inside a source file - either an SQL string inside an host language or some lines from a
.sql
file - but dadbod-ui only supports running SQL queries from its own buffer queries. It would be nice if we the:DBUI
panel had an option to setg:db
so that we can use dadbod-ui to manage the database connections and regular dadbod's:DB
to run queries from source files.The text was updated successfully, but these errors were encountered: