Closed patata3000 closed 10 months ago
+1 to this. Tested it on multiple remote DBs as well as a handful of local ones. Seems to work well. Could this be reviewed? I feel like this would be a great addition to this otherwise great product.
It was added to fix this issue https://github.com/kristijanhusak/vim-dadbod-ui/issues/90. I need to double-check everything before merging this in if nothing breaks.
Did you try to use async option on dadbod-ssh (https://github.com/pbogut/vim-dadbod-ssh/blob/master/autoload/db/adapter/ssh.vim#L21-L22) ? I see in the comment that the author is mentioning DBUI, so I'm assuming it's working for them.
I don't think we will be able to apply this PR because db#resolve
is needed for some other adapters.
This might be solvable on the dadbod-ssh level.
Can you try commenting out this function locally in dadbod-ssh https://github.com/pbogut/vim-dadbod-ssh/blob/master/autoload/db/adapter/ssh.vim#L177-L180 and testing if everything works? filter
and interactive
should set up a tunnel, there's no need to do it on canonicalize level.
I tried your suggestion and it reconnects successfully, querying works fine ,and the tunnel auto closes when I exit vim. However, table columns don't show when I expand them.
This only happens in ssh connections, local ones still work normally.
I'll try to figure out why this is happening but it's going to take quite some time since I'm not familiar with vimscript or dadbod. Oh yes and here's my fork if anyone's interested https://github.com/eslam-allam/vim-dadbod-ssh.
[Edit] Can I get a brief explanation about canonicalize and it's usage to lead me in the right direction?
I found the issue. Scheme returned for this connection is ssh
and not the underlying db like mysql
. I'll fix that and let you know to give it another test.
canonicalize
is in charge of "fixing" the URL to a correct format. If you check canonicalize on MySQL and Postgres in vim-dadbod, you should get the idea.
Ok I pushed a change to master that should fix that. Can you give it a try?
No effect unfortunately.
Did you grab the latest master changes?
If yes, can you apply this patch locally to the vim-dadbod-ui
plugin, connect to the db and provide me what was printed in the cmdline? Just mask the sensitive data. I just need to see if this URL starts with ssh
or not. It shouldn't.
diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim
index 0c5417b..2582891 100644
--- a/autoload/db_ui.vim
+++ b/autoload/db_ui.vim
@@ -383,6 +383,7 @@ function! s:dbui.connect(db) abort
let query_time = reltime()
call db_ui#notifications#info('Connecting to db '.a:db.name.'...')
let a:db.conn = db#connect(a:db.url)
+ echom string(a:db.conn)
let a:db.conn_error = ''
call self.populate_schema_info(a:db)
call db_ui#notifications#info('Connected to db '.a:db.name.' after '.split(reltimestr(reltime(query_time)))[0].' sec.')
Well actually, it will return ssh://
, so there is no effect.
@eslam-allam did you try this PR? I think it should have the same problem as you have now regarding the table helpers. The simplest solution would be to bake this in the plugin, because I can't figure out a workaround.
Idea is similar to this PR, but not call db#resolve
only for ssh
connections. I'll do the changes and let you know.
@eslam-allam I added the changes. Pull the latest master, remove the changes done to vim-dadbod-ssh
, and try re-adding the connection. It applies the same idea as this PR, but with a wrapper function.
Works like a charm! Tried it with both local and ssh. The queries work as expected. Autocomplete works (Tablenames and fields). Thanks alot :)
Awesome :) Closing this as resolved. Thanks for helping out!
Right now, I cannot use dadbod-ssh with ui because whenever I save an URL, the saved URL is resolved before saving. With ssh adapter, the url points to a localhost:7000 after resolving (or so). This is the URL that is saved in connection.json.
Then when I close nvim and try to reopen connection to the database, the local port (7000) is closed. dadbod-ui is trying to open it without opening ssh tunnel because url is not saved with the ssh:/ prefix (as it is resolved).
Here I removed the db#resolved from the saved url and from the added connections.
I probably missed something as they were probably there for a reason. In this case, please feel free to tell me what I'm missing for this to be accepted.
However, I don't understand why dadbod-ui has his own version of adapters. vim-dadbod let's you write some so why not adding adapters directly to vim-dadbod? Please enlighten me on the matter
Disclaimer : I've never written anything in vimscript