# Connection as code

> Connection as code means a dashboard's data sources are named, declarative objects that specs reference by name, with credentials held apart from the specs.

Canonical: https://dvt.dev/glossary/connection-as-code/

Connection as code is the practice of treating a dashboard tool's data sources as named, declarative objects that dashboards reference by name, with credentials kept apart from the dashboard specs rather than embedded in them.

It applies the [BI-as-code](https://dvt.dev/glossary/bi-as-code) idea to the part of the stack that is usually set up once in a settings screen and then forgotten. When connections are named objects, a reviewer can see which source a dashboard reads from without ever seeing a secret.

## How it works in dvt

A dvt connection is a named object with a `type` (Snowflake, Postgres, BigQuery, or Google Sheets), an auth method, and the non-sensitive settings that type needs: a Postgres `host` and `database`, a BigQuery `project`, or a Google Sheets `spreadsheetId`. Credentials are stored envelope-encrypted and are never returned to a client, so they cannot leak into a spec, a screenshot, or an agent's context.

The connection's name is the `sourceId` a [panel](https://dvt.dev/glossary/dashboard-panel) references, so every chart in a [dashboard spec](https://dvt.dev/glossary/dashboard-spec) states exactly which source it queries. dvt connects to [Snowflake](https://dvt.dev/solutions/snowflake-ai-dashboards), [Postgres](https://dvt.dev/solutions/postgres-ai-dashboards), [BigQuery](https://dvt.dev/solutions/bigquery-ai-dashboards), and [Google Sheets](https://dvt.dev/solutions/google-sheets-dashboards) this way, and runs each panel's query against that source when the dashboard is viewed.

## Related terms

- [SQL pushdown](https://dvt.dev/glossary/sql-pushdown)
- [Dashboard spec](https://dvt.dev/glossary/dashboard-spec)
- [BI as code](https://dvt.dev/glossary/bi-as-code)
- [Dashboards as code, the dvt implementation](https://dvt.dev/solutions/dashboards-as-code)
