Allow Dynamic Selection of DB Connection Params

the DB host, port, user, password and DB can be hardcoded only as of now.

would like for these data points to be allowed to select from ENV variables.

we do not want to set it up via target coz those targets are still visible to all devs who have access to the git repo - if it is part of ENV variables, then we can secure the access of credentials to only those who have access to PROD environment, not all devs. working a team and large projects makes this imperative for us!

we tried to replace these values with {{$_ENV.var_name}} directly in the JSON file for DB conn. that works as expected actually at run time.

however, it breaks Wappler UI itself - we can no longer work with queries/steps that connect with DB to show the list of tables and schema of those tables.
would like for this to work without breaking Wappler!

if selecting from ENV is allowed on DB Conn Options natively within Wappler, it’ll be very convenient. we do not wish to hack our way through setting this up and taking care with each deployment.

please consider this.

thank you.

Bumping this request.

@George I found an older post about using Environment variables for DB connection.
Is this no longer possible? Same HTML files but different database connections for subdomains

Like @nshkrsh has pointed, if we set ENV variables, the query builders stop working in the UI.

I too would find this very useful.

Well ENV variables should work indeed, if they are set.

Try to display them and also the connection error you got.

I think the last time we were trying this, we did something wrong.
This time, I took it a bit slow, and identified that JSON with connection string for DB Manager is different from the connection string for Globals DB Connection.
All I needed was to play around with the Globals JSON.
Keeping the DB Manager values unchanged, I can connect to dynamic DB based on ENV.
When developing on local, I can still access all query builder UIs.

In my case, I had to get a bit creative with putting a complete JSON in ENV, but as a concept, what you have suggested works. :slight_smile:

There is one bug here, in addition to what Nishkarsh has asked for -

  1. Need dynamic picker in UI to select ENV variable instead of having to type.
  2. Port field is restricted to number, so cant bind without going in code view of the JSON file.

To add a little context, we use Caprover for deploying. Which is based on commits.
When using targets in Wappler with DO (or other) Docker setup, everything is handled by target automatically.
But when deploying with Git, the target stuff does not really work well for us.
Now, with ENV setup, everything is in sync.

This is the major reason for this request.
I understand this might not be a concern for majority of Wappler users - but in larger projects where it matters it’s a make-or-break situation, hope you can understand the severity of this.

Really hope we can get this sorted soon. Meanwhile, can you guys post a picture of what do I need to change to make the app read from ENV? And do I create a “Production” target?

You need to change the connection string in JSON file located at: {{root}}\.wappler\targets\{{Development}}\app\modules\connections.

It should look something like:

If you have a production target that uses Wappler to deploy, same config would be needed for that as well. Both files should be same at then end.

1 Like

I’m trying to deploy with Caprover as well.

I made that change on the file you’ve pointed, but when I deploy to Caprover it seems the NodeJS app is reading the file at app/modules/connections/db.json instead of .wappler/targets/Development/app/modules/connections/db.json, as it attempts to find the hostname “db” (as written on app/modules/connections/db.json ) instead of $_ENV[‘DB_HOST’] (as written on .wappler/targets/Development/app/modules/connections/db.json).

Do you have any hints on how to solve this?

P.S.: I’ve created a .env file on my local computer (ignored on Git) , and inserted DB_* variables on Caprover’s dashboard

Thats not caprover. Thats how Wappler works. And its correct.

When you select a target, values from target folder gets copied into the app json file.
So, both dev and prod need to have same config - from ENV.
So, when you commit your code, irrespective of target, what is deployed to Caprover is ENV setup always.

1 Like

bumping this request

bumping this request.

You can fully change the connection properties in the Database Connections within the Server Connect Globals, with dynamic environment variables.

You just have to make sure that the database connection used in the Database Manager is not changed and just points to the direct connection with the right credentials so Wappler can still access your database.

So to resume just change only in Server Connect global database connections and everything should work fine.

1 Like

Also make sure for you local development you have set the environment variables in a .env file

1 Like

this will be deployed to Wappler next version, right?
am on 4.8.3 and cannot still see picker on the globals DB picker.

in this case, have manually updated the file directly with mappers, neither the mapper shows nor picker.

You can directly enter {{$_ENV['property_name']}} in the UI on your screenshot and it should be working fine.

not convenient. picker would be desirable. to make it ‘visual’ and convenient.

also, for port, entering text does not work. that field expects numbers only.
on pasting you can see the text, but as soon as focus is lost from the field, it turns back to blank.

better way would be to allow for selection via pickers.



This is now implemented in Wappler