Variable Substitution in Connection Settings
DBCode supports variable substitution in connection settings so you can reference files (like service account JSON or private keys) without hard coding absolute paths. This makes connection configs portable across machines and team members.
When To Use It
- Reference files checked into your repo (e.g.,
${workspaceFolder}/secrets/credentials.json
) - Support different local paths for each teammate
- Keep credentials in consistent project locations without absolute paths
Supported Variables
${workspaceFolder}
: Path of the folder opened in VS Code${workspaceRoot}
: Alias for${workspaceFolder}
${home}
: User home directory${env:VARIABLE_NAME}
: Value from the environment- Relative paths: Interpreted relative to the workspace folder (e.g.,
secrets/key.json
)
Resolution Order
- Use the path as is if it’s an absolute file path and exists
- Resolve
${home}
if present - Resolve
${env:...}
variables if present - For each workspace folder:
- Substitute
${workspaceFolder}
/${workspaceRoot}
- Try the path as workspace relative
- Substitute
- If no resolution succeeds, connection fails
Example
Configure a BigQuery/Firebase service account key stored in your repo:
{ "dbcode.connections": [ { "connectionId": "my-service-account", "name": "My GCP Project", "driver": "bigquery", "driverOptions": { "authType": "sa", "key": "${workspaceFolder}/secrets/credentials.json" } } ]}
You can also use environment variables, for example:
{ "driverOptions": { "key": "${env:CREDENTIALS_DIR}/gcp.json" }}
Where It Applies
File based fields in driverOptions
automatically support variable substitution, including (but not limited to):
- BigQuery:
key
(service account JSON) - Firebase:
key
(service account credentials) - Snowflake:
key
,keyFile
,keyFilename
,privateKeyPath
(private key files)
Additionally, file based drivers (e.g., SQLite, DuckDB) support variables in their file paths.
Behavior And Errors
- Resolution happens only when connecting;
- If a file can’t be found after resolution, the connection is aborted.