Git Product home page Git Product logo

Comments (12)

skriems avatar skriems commented on May 21, 2024 2

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.

kristijanhusak avatar kristijanhusak commented on May 21, 2024 1

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.

kristijanhusak avatar kristijanhusak commented on May 21, 2024 1

@skriems support for env variables was added. Check this part of readme: https://github.com/kristijanhusak/vim-dadbod-ui#databases

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024 1

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.

skriems avatar skriems commented on May 21, 2024 1

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.

kristijanhusak avatar kristijanhusak commented on May 21, 2024 1

This feature is added. Check this part of readme:
https://github.com/kristijanhusak/vim-dadbod-ui#via-dbuiaddconnection-command

from vim-dadbod-ui.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@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.

skriems avatar skriems commented on May 21, 2024

@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.

skriems avatar skriems commented on May 21, 2024

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.

alalfakawma avatar alalfakawma commented on May 21, 2024

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.

kristijanhusak avatar kristijanhusak commented on May 21, 2024

@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.

alalfakawma avatar alalfakawma commented on May 21, 2024

Great job @kristijanhusak. Also, thanks for clearing things up @skriems. It now works. Great stuff.

from vim-dadbod-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.