Comments (12)
It would be awesome to leverage tpope's dotenv plugin as well and get connections from environment variables. Assuming that most projects use a .env file (if not only for docker-compose) anyway, you could use that to setup your db connections
from vim-dadbod-ui.
Yeah adding it from the GUI could be the option, but i would have to save that config somewhere.
Currently you can solve this by having a project local vimrc (see :help exrc
), add it to .gitignore
and define the connections there. So once you open your project, you should have all your databases set up.
from vim-dadbod-ui.
@skriems support for env variables was added. Check this part of readme: https://github.com/kristijanhusak/vim-dadbod-ui#databases
from vim-dadbod-ui.
Unfortunately it's not possible to set env variable to anything other than a string. If it would accept some kind of array, that would be nice.
If i would parse something by the part of the env variable name, i would have to read all env variables. That's a bit too much.
If you need more than 1 connections, i would suggest to use project specific vimrc with g:dbs
, put it in global gitignore, and you should be good to go. That's how I use it since i have a lot of connections set up.
This env variable is just a nice addition.
I also plan to add the initial suggestion of this issue, so that will also cover your case in a way.
from vim-dadbod-ui.
hey alalfakawma,
so first of all I think there's a race condition in the loading order of dadbod-ui and dotenv.vim (I guess due to alphabetical loading of plugins?). The first time dadbod-ui tries to get information from the env, dotenv.vim hasn't populated values from the .env file yet - load another file and you should be good.
2nd, I think you have confused the g:db_ui_env_variable_name
with the name of the database. If you don't want to use a prefix in your .env file, you can still use g:db_ui_env_variable_url
but this needs to be the full URL to your database, i.e.
postgres://<user>:<password>@<host>:<port>/<db_name>
dadbod-ui then tries to extract the <db_name>
as the name in the UI and only if it fails, you can use g:db_ui_env_variable_name
to overwrite/specify one.
With this in mind, I suspect that you need to build a dedicated env variable in your .env file, because DB_HOST
and DB_DATABSE
usually only refert to parts of the whole string like above
from vim-dadbod-ui.
This feature is added. Check this part of readme:
https://github.com/kristijanhusak/vim-dadbod-ui#via-dbuiaddconnection-command
from vim-dadbod-ui.
@skriems i plan to do that. My only concern is that i don't have the name for the connection. I could probably extract it from the url.
from vim-dadbod-ui.
@kristijanhusak I guess I would use a (optionally configurable) prefix for env variables which could default to DBUI_
. The rest of it lowercased could become the name maybe
from vim-dadbod-ui.
cool, that was fast @kristijanhusak :)
However I think this is not as flexible as users might need it to be. A project I'm working on currently has two db servers with the same db name, so this wouldn't work perfectly for me (actually I only have to connect to one, so...). Anyhow, I guess I would prefere extracting the name from the env variable instead of the connection string.
But this is cool stuff nevertheless :D
needs to get involved in writing vimscript
from vim-dadbod-ui.
This is real sick. Thank you for the quick follow up.
EDIT: I'm not able to use this with Laravel, Laravel creates a .env
file in the root project folder and I have set
let g:db_ui_env_variable_url = 'DB_HOST'
let g:db_ui_env_variable_name = 'DB_DATABASE'
these in my .vimrc
which is supposed to do the trick, as DB_HOST and DB_DATABASE are .env
vars that Laravel uses, but when running :DBUI
I get an error saying no databases were found, you have to define.... Can you please guide me or tell me if i'm doing something wrong?
from vim-dadbod-ui.
@skriems is right for everything. For dotenv to load the env variables, some file must be opened to trigger it. I tried to go around it, but it's not doing the trick.
from vim-dadbod-ui.
Great job @kristijanhusak. Also, thanks for clearing things up @skriems. It now works. Great stuff.
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.