Snowflake: Dynamically use different databases not specified in the Resource Connection

Hi Retool users/devs

I am trying to migrate resource queries that currently access the dev environment to now access the prod and dev enviornments.

For example:
I have an insert script that is currently inserting and pulling from the dev environment. But after refactoring and configuration, I want to be able to access the raw database while also querying from a dev database.

How can I ensure that one Resource connection can access different databases in one resource query?