Comments (10)
There's already a command that allows you to partially use this.
For example, if you have an sql file, you can use :DBUIFindBuffer
. It will prompt you for db which you want to assign to it, or use the first one if there's only one in the list. From there you can use that buffer as it is a dbui buffer.
This is not working for non sql filetypes, because dbui converts it to sql filetype. I plan to improve that.
from vim-dadbod-ui.
I did the improvement. Now you can assign any filetype to dbui with :DBUIFindBuffer
. It will not mess up the filetype or anything.
It should also allow using vim-dadbod-completion
completion, but you need to make sure that it's included for your non-sql filetype. So if you use coc, you must include this in your coc config:
coc.source.db.filetypes: ['sql', 'yourfiletypehere']
If you can give it a test and let me know how it looks.
from vim-dadbod-ui.
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 :DBUIFindBuffer
I can only execute its entire content - which is obviously not valid SQL. It's also not useful to have dbui automatically execute it as query on save...
from vim-dadbod-ui.
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 <Leader>S
in sql buffers. Problem is that it's not mapped for non-sql buffers, so you would have to do that manually. I think optimal setup for your case would be this:
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 :DBUIFindBuffer
in your c file, visual select SELECT * FORM foo;
, and press <Leader>S
. This should execute that selection only. If you use vim-dadbod-completion, you should also get completion for the selected database.
from vim-dadbod-ui.
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()
from vim-dadbod-ui.
Which part doesn't work?
from vim-dadbod-ui.
I made a mistake in my comment, it shouldn't be vnoremap
but vmap
:
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 [{ name: db_name, url: db_url }]
through db_ui#get_conn_info
so you can use your fzf?
from vim-dadbod-ui.
The mapping doesn't work. I see [DBUI] Executing query...Done after 0.042320 sec.
but no result window is opened.
At any rate I'd still prefer to set b:db
(or g:db
) and keeping g:db_ui_execute_on_save
on because it is useful in actual dbui buffers, so a db_ui#list_conns()
or something would be nice...
from vim-dadbod-ui.
That's odd. Does it work if you try to execute visual selection in dbui sql buffer?
I added db_ui#connections_list()
function, which returns name
, url
, source
and is_connected
properties.
from vim-dadbod-ui.
Weird - I tried the mapping again after updating the plugin, and it worked...
Anyway db_ui#connections_list()
works like a charm. Thanks!
from vim-dadbod-ui.
Related Issues (20)
- Table Structure not showing properly. HOT 2
- Store query time per dbout buffer
- Ability to remove, reorder (or sort) preset table helpers
- Move the DBUI section to right HOT 1
- Possible to Add Option for Nvim-Notify to Track Query Time? HOT 4
- Keep the query output open while updating the query HOT 1
- Open query results in a window instead of a buffer
- Feature Request: Enhance Foreign Key Lookup to Consider Current Database Context in `schemas.vim`
- Cursorline and default mappings HOT 2
- DBUI stop working when given a wrong connection HOT 1
- Support for a new database HOT 3
- Table format off when text field includes line breaks HOT 1
- FR: Put views into a separate category
- Are there any options for "edit current entry" when browsing the result of a query?
- Duplicate tag "ic"
- Move Buffer output dropdown to respective database
- Show connection string of database HOT 1
- Oracle database not opening up properly HOT 10
- bind parameter delimiter config HOT 2
- Change `search_path` for session duration?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-dadbod-ui.