Missing a way to read env variables in the db connection files

Does node parse that expression when coming from the json file? When I tried it treated it as text.

Well it depends how you read the json file.

$_ENV variables are just available in all server connect settings and expressions.

Nono, I mean Wappler’s json connection file. The one in /app. To set an environment variable inside the app/modules/connections/db.json so I can set the appropriate variables in the server an use the same connection file name for all environments.

Yes you can fully use them there!

Just enter all the server connect database connection properties on the dialog as expressions like {{$_ENV[“dbname”]}}

I guess we can add a data picker there as well.

I believe it’s not parsed.

image

Hmm should be - @patrick will check it out

1 Like

The options for the connection do currently not accept expressions. Please test the following update, place the file in lib/core.

app.zip (2.5 KB)

2 Likes

Thanks @patrick

I confirm it works.

For my use case it would be enough to be able to add environment variables in the target that are loaded on server start. Plus the picker you mention of course.

@George

Just to mention that this approach is not compatible with the db manager. If these environment variables could be set in the target they could be read by the db manager.

1 Like

Yes indeed db manager needs real values for its direct connections.

But isn’t that ok? You need direct connections to manage your database. While in server connect you can use variables?

Yep. Indeed that would be ideal.

I need to do some testing but the DB manager values also got overwritten by the variables when setting them.

Hi @George ,

Indeed it is being overwritten.

I set up SC Connection with the variables then I set Direct Connection with the real values and the SC connection variables get overwritten with the real values.

As a workaround I use an external editor to edit manually the files. So just so you guys know.

This has been improved in Wappler 4.9.0

This topic was automatically closed after 2 days. New replies are no longer allowed.