<!-- https://testapilocally.com/docs/core-features/database/ -->
# Database workbench

* **Platform Availability:** Windows App · VS Code Extension (shared shell + DB host)
* **Overview:** Connect to PostgreSQL, MySQL, SQL Server, Oracle, or SQLite (plus a sample catalog), run SQL, inspect schema, and manage results — local-first with an optional vault for passwords.

![Windows - DB workbench](/docs/assets/screenshots/windows/windows-db-workbench.png)

## How It Works (Windows App)

1. Switch to **DB** mode.
2. Add a connection; pick a driver; fill host/user/database (or file path for SQLite).
3. Store passwords in the vault when prompted.
4. **Test** connection, then open the SQL editor.
5. Run with **Ctrl+Enter** (or Run all with **Ctrl+Shift+Enter**).
6. Review result tabs; export/copy; use transactions where supported.

![Windows - DB connection](/docs/assets/screenshots/windows/windows-db-connection.png)

## How It Works (VS Code Extension)

1. Open SignOff Studio → **DB** mode.
2. Same workbench UI; DB proxy/drivers run through the VS Code host (`db-proxy` / driver packs).

![VS Code - DB workbench](/docs/assets/screenshots/vscode/vscode-db-workbench.png)

## Drivers

| Driver | Notes |
|--------|-------|
| Sample catalog | Built-in learning data |
| PostgreSQL | `pg` |
| MySQL | `mysql2` |
| SQL Server | `mssql` |
| Oracle | `oracledb` |
| SQLite | `better-sqlite3` / file path |

## Code / Configuration Examples

```sql
SELECT id, email, created_at
FROM users
WHERE active = true
ORDER BY created_at DESC
LIMIT 50;
```

Scripting bridge (when host allows):

```javascript
const rows = await qa.db.query("SELECT 1 AS ok");
qa.expect(rows[0].ok).to.equal(1);
```

## Edge Cases, Troubleshooting & Pro-Tips

- If connections fail after update, check **driver overlays** (status / update / rollback).
- Query timeout and kill session are available for long-running statements.
- Format SQL with **Ctrl+Shift+F**.
- With no query tab open, the workbench shows a launchpad (new SQL, join synthesis, import, schema docs, pinned tables, and parameterized runbooks) and a rotating database tip.
- Stage two to four Explorer tables with Ctrl/Cmd+click or the fork icon. The tray above the inspector builds the shortest foreign-key join, including bridge tables. Inferred keys start as `LEFT JOIN`.
- **Import CSV / JSON** reads `.csv`, `.json`, and `.ndjson`, infers column types from the first 250 rows, and runs the batch in a transaction.
- **Export Schema Docs** copies Markdown with a Mermaid `erDiagram` plus a column dictionary. Explicit foreign keys use `||--o{`; inferred keys use `||..o{`.
- Narrower than 900px (a VS Code split pane), secondary SQL toolbar buttons become icons. **Ctrl+B** or the `◧` button collapses the Explorer. Inside VS Code, the host may use Ctrl+B for its own sidebar; the button still collapses the workbench drawer.

## Next

- [Workspaces](/docs/core-features/workspaces/)
- [Tests & scripts](/docs/core-features/tests-scripts/)
