Folder Connections
Set a connection and database for a folder, and DBCode automatically uses it for any .sql file you open inside that folder - so you don’t have to pick a connection each time. Subfolders inherit the folder’s connection, so new files and folders just work.
This is useful when a single workspace holds SQL for several databases at once, where each folder maps to a different environment, module, or business.
Setting a Folder’s Connection
Section titled “Setting a Folder’s Connection”Right-click any folder in the VS Code file explorer and select Set Folder Connection with DBCode, then choose the connection and database for that folder.
Now open a .sql file under that folder and DBCode selects that connection for it automatically - you’ll see it in the status bar and code lens, with no prompt. The choice is saved to your workspace settings.
How It Works
Section titled “How It Works”A folder connection is the default DBCode uses for .sql files inside the folder that don’t already have a connection of their own. When you open such a file, DBCode finds the most specific folder connection that matches the file’s path and assigns it:
- Subfolder inheritance - a connection set on
reports/applies to every.sqlfile beneath it, including ones in subfolders you create later. There’s nothing to update as the folder structure grows. - Most specific wins - if you’ve set a connection on both
reports/andreports/prod/, files inreports/prod/use thereports/prod/connection. - Your choice always wins - the folder connection is only a default. If you pick a connection for a specific file yourself (from the status bar or code lens), DBCode remembers that choice for the file and uses it instead.
A folder connection is a default, not a lock. DBCode never silently switches a file: the assigned connection is always shown in the status bar and code lens, so you can see which database a file is set to before you run anything.
Configuration
Section titled “Configuration”Folder connections are stored in the dbcode.connectionBindings setting as an array:
"dbcode.connectionBindings": [ { "path": "reports/sales/**", "connectionId": "...", "database": "sales" }, { "path": "reports/ops/**", "connectionId": "...", "database": "ops", "schema": "public" }]| Field | Description |
|---|---|
path | A glob matched against the file’s workspace-relative path. Use <folder>/** to cover everything under a folder. |
connectionId | The connection to assign. The Set Folder Connection with DBCode command fills this in for you. |
database | The database to use. |
schema | Optional schema, for connections that support schemas. |
The setting is resource-scoped, so folder connections can be defined at the user, workspace, or folder level. Paths are workspace-relative, so workspace-level settings are portable across machines when the workspace is shared via version control.
If a folder points at a connection that isn’t available on the current machine, it’s skipped and the file falls back to prompting for a connection as usual.