kristijanhusak / vim-dadbod-ui

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

Is it possible to open a connection as READONLY? #273

Open brunobmello25 opened 2 months ago

brunobmello25 commented 2 months ago

Similar to a connection option we have in datagrip. This is really handy when connecting to production databases for debug purposes: where we definitely want to avoid running a write query by mistake.

kristijanhusak commented 2 months ago

Which DB? I wanted to add something like that, but it's a bit tricky to hook into the connection to add it, at least for postgres.

brunobmello25 commented 2 months ago

Which DB? I wanted to add something like that, but it's a bit tricky to hook into the connection to add it, at least for postgres.

It's postgres. Yeah, I was trying to figure out how to make it readonly within the connection url but couldn't really find an answer myself either =/ Maybe I could try to figure out how datagrip does so we can have some sort of reference

titaniumtraveler commented 1 month ago

AFAIK that should be possible, by configuring vim-dadbod to use the right postgresql-role. (See https://www.postgresql.org/docs/17/role-membership.html) I'm not sure which role attributes you would have to give it though.

jay-babu commented 1 month ago

+1 would also like this. @kristijanhusak, https://stackoverflow.com/questions/41960217/connecting-to-postgres-database-with-read-only-access. is it possible to run this after connecting? I would explicitly run something to make it read write obviously. I see table helpers, https://github.com/kristijanhusak/vim-dadbod-ui#table-helpers, however I don't think that would work. Maybe if there was auto command like post connect, i could run the set session read only

kristijanhusak commented 1 month ago

@jay-babu each query is run as a separate call, there is no persistent connection. I'm thinking of modifying the query before it's executed to achieve this, but I still need to do some thorough testing on it.

jay-babu commented 1 month ago

@jay-babu each query is run as a separate call, there is no persistent connection.

I'm thinking of modifying the query before it's executed to achieve this, but I still need to do some thorough testing on it.

Oh hmmm. It doesn't grab and hold a connection/session, I see. If there was a way to run pre and post scripts that'd work too. Maybe just like auto commands in nvim