Add A Backend
Adding a backend should keep backend-specific behavior behind the existing seams instead of spreading switch logic through commands.
Decide The Backend Shape
Section titled “Decide The Backend Shape”Before writing code, define:
- Connection
optionssuch as host, port, user, account, or path. - Runtime
contextkeys such as database, schema, warehouse, or role. secretsreferences such as password env vars or key passphrase env vars.- Inspect capabilities that are real for the backend.
- Statement actions that tonic should authorize and forward.
Do not fake catalog, namespace, or DDL support just to match another backend.
Main Code Paths
Section titled “Main Code Paths”| Area | Files |
|---|---|
| Config model | internal/config/config.go, internal/config/config_test.go |
| Backend open/summary | internal/backend/ |
| Target resolution | internal/target/target.go |
| Connections CLI | cmd/connections_add.go, cmd/connections_show.go |
| Query execution | internal/queryexec/ |
| Inspect runtime | internal/dbinspect/ |
| CLI inspect wiring | cmd/inspect_*.go |
Implementation Order
Section titled “Implementation Order”- Add config parsing, normalization, validation, YAML marshal/decode support, and tests.
- Register a backend implementation in
internal/backend. - Verify target resolution and secret loading.
- Add
connections add <backend> NAMECLI support. - Confirm query execution works through
database/sqland backend context application. - Register inspect support or explicit unsupported errors.
- Add real tests where practical.
- Update docs and the command reference.
Live Checks
Section titled “Live Checks”Run realistic commands before calling a backend done:
go run . connections add <backend> <name> ...go run . connections show <name>go run . query ping --target <name>go run . query exec --target <name> --sql 'select 1'go run . inspect tables --target <name>go run . query exec --file path.sqlFinish with:
go test ./...