====== Query Console ======
The Query Console gives you direct SQL access to the CodeDB database. Write queries, explore your data, and export results.
===== Opening the Query Console =====
- Press **⌘J** to toggle the bottom panel
- Click the **Query Console** tab
===== SQL Editor Mode =====
The SQL editor lets you write and run raw SQL queries against the database.
- Type your SQL in the text area
- Click **▶ Run** or press the run button to execute
- Results appear in a table below
=== Available Tables ===
^ Table ^ Description ^
| ''files'' | All files stored in CodeDB (id, name, path, content, language, created_at, updated_at) |
| ''relations'' | Connections between files (id, source_id, target_id, relation_type, metadata) |
| ''tags'' | Tags on files (id, file_id, tag) |
| ''properties'' | Key-value metadata on files (id, file_id, key, value) |
| ''smart_views'' | Saved Smart View queries (id, name, query, icon) |
=== Example Queries ===
**Count files by language:**
SELECT language, COUNT(*) as count
FROM files
GROUP BY language
ORDER BY count DESC;
**Find all dependencies for a file:**
SELECT f2.name as depends_on, r.relation_type
FROM relations r
JOIN files f1 ON r.source_id = f1.id
JOIN files f2 ON r.target_id = f2.id
WHERE f1.name = 'app.js';
**Files with specific tag:**
SELECT f.name, t.tag
FROM files f
JOIN tags t ON f.id = t.file_id
WHERE t.tag LIKE '%api%';
**Most connected files:**
SELECT f.name, COUNT(r.id) as connections
FROM files f
LEFT JOIN relations r ON f.id = r.source_id OR f.id = r.target_id
GROUP BY f.id
ORDER BY connections DESC
LIMIT 10;
===== Query Builder Mode =====
The Query Builder provides a visual interface for constructing queries without writing SQL:
- **Table:** Select the base table to query
- **Columns:** Choose which columns to include
- **Joins:** Add joins to related tables
- **Where:** Add filter conditions
- **Order:** Sort results by any column (ASC or DESC)
- **Limit:** Restrict the number of results
The generated SQL preview updates live as you build. Click **▶ Run** to execute.
===== Export Options =====
Query results can be exported in multiple formats:
* **JSON** — structured data export
* **CSV** — spreadsheet-compatible export
* **Mermaid** — graph diagram syntax for visualization tools