User Tools

Site Tools


codedb:query-console

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

  1. Press ⌘J to toggle the bottom panel
  2. Click the Query Console tab

SQL Editor Mode

The SQL editor lets you write and run raw SQL queries against the database.

  1. Type your SQL in the text area
  2. Click ▶ Run or press the run button to execute
  3. 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:

  1. Table: Select the base table to query
  2. Columns: Choose which columns to include
  3. Joins: Add joins to related tables
  4. Where: Add filter conditions
  5. Order: Sort results by any column (ASC or DESC)
  6. 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
codedb/query-console.txt · Last modified: by 127.0.0.1