Silverstripe 4.x Database Environment Variables?

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version:
4.x
Question:

In Silverstripe 4.x, how do I get DB credentials with environment variables, instead of using the .env file? For instance, in app/_config.php, I tried something like:

if (getenv('SS_DATABASE_NAME')) {
	define('SS_DATABASE_NAME',  getenv('SS_DATABASE_NAME'));
}

I’ve also tried in in app/_config.php:

use SilverStripe\Core\Environment;
Environment::setEnv('SS_DATABASE_NAME', 'mydb');

In both cases I get:
“Silverstripe Framework requires a “database” key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?”