kristijanhusak / vim-dadbod-ui

Simple UI for https://github.com/tpope/vim-dadbod
MIT License
1.48k stars 86 forks source link

Function to generate connection string #251

Closed itmecho closed 2 months ago

itmecho commented 3 months ago

Thanks for the great plugin!

I know this plugin isn't written in lua so I'm not sure if this would be possible but it would be really useful to be able to pass a function in place of a connection string. For example:

local function someSetupFunction()
  -- Do stuff here to prepare the connection string
  return 'postgres://user:pass@localhost:5432/db'
end

vim.g.dbs = {
  { name = 'test', url = someSetupFunction },
}

That would enable doing things like port forwarding a private database host or fetching a password from a secret manager when you select a database from the list and only connecting once the setup is complete.

My current solution for this is to port forward all of the databases and fetch all the passwords as part of the lazy.nvim config function which is triggered when I run the DBUI command. However, this is pretty slow as it's doing a lot of unnecessary work when I might only need to connect to a single database.

Kurren123 commented 2 months ago

+1 I would really like this. Most of my sql queries are executed on my local db so I don't want to always have to do :DBUIAddConnection sqlserver://localhost;integratedSecurity=true;database=MyDatabase. Ideally I would just need to do :AddLocalDb MyDatabase

kristijanhusak commented 2 months ago

This is now added. See example for production in https://github.com/kristijanhusak/vim-dadbod-ui#via-gdbs-global-variable

itmecho commented 2 months ago

Thanks @kristijanhusak! That's amazing 😄