Skip to content

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.

  • 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
  • ${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)
  1. Use the path as is if it’s an absolute file path and exists
  2. Resolve ${home} if present
  3. Resolve ${env:...} variables if present
  4. For each workspace folder:
    • Substitute ${workspaceFolder} / ${workspaceRoot}
    • Try the path as workspace relative
  5. If no resolution succeeds, connection fails

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"
}
}

SSL key material can live alongside your project as well:

{
"dbcode.connections": [
{
"connectionId": "prod-postgres",
"name": "Production",
"driver": "postgres",
"host": "mydb.company",
"sslCACert": "${workspaceFolder}/certs/ca.pem",
"sslClientCert": "${workspaceFolder}/certs/client.crt",
"sslClientKey": "${home}/.certs/client.key"
}
]
}

File based fields in connection definitions 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)
  • SSL options: sslCACert, sslClientCert, and sslClientKey

Additionally, file based drivers (e.g., SQLite, DuckDB) support variables in their file paths.

  • Resolution happens only when connecting;
  • If a file can’t be found after resolution, the connection is aborted.