ql lets developers query codebases with SQL.
It parses source files with Tree-sitter, maps syntax into language-agnostic tables, loads rows into DuckDB, and runs SQL against those tables. Goal: deterministic code search and analysis without AI, embeddings, or fuzzy guesses.
From a checkout:
cargo build --release
./target/release/ql --langsOr install the binary locally:
cargo install --path crates/ql-cli
ql --langsql "SELECT name, file, line
FROM functions
WHERE complexity > 10
AND has_test = false" ./srcLanguage adapters populate the shared schema:
functionscallsimportsstructsvariablescommentsfn_fingerprints— structural metrics per functionfn_callsets— callee sets per functionsimilarities— pairwise similarity scores
Schema source lives in schema/tables.json.
All examples assume you run them from a repository root or pass an explicit path as the final argument.
- Find non-test functions with higher complexity.
ql "SELECT name, file, line, complexity FROM functions WHERE has_test = false AND complexity > 10 ORDER BY complexity DESC" .- List all external calls.
ql "SELECT caller, callee, file, line FROM calls WHERE is_external = true ORDER BY file, line" .- Inspect imports from the standard library.
ql "SELECT module, alias, file, line FROM imports WHERE is_std = true ORDER BY file, line" .- Find public structs and their implemented interfaces.
ql "SELECT name, visibility, implements, file, line FROM structs WHERE visibility = 'public' ORDER BY file, line" .- List mutable variables.
ql "SELECT name, type_hint, scope, file, line FROM variables WHERE is_mutated = true ORDER BY file, line" .- Show doc comments attached to code.
ql "SELECT text, attached_to, file, line FROM comments WHERE is_doc = true AND attached_to != '' ORDER BY file, line" .- Find functions that mention tests.
ql "SELECT name, file, line FROM functions WHERE has_test = true ORDER BY file, line" .- Show functions that return results.
ql "SELECT name, return_type, file, line FROM functions WHERE return_type LIKE '%Result%' ORDER BY file, line" .- Render the same data as JSON.
ql --format json "SELECT name, file, line FROM structs ORDER BY file, line LIMIT 20" .- Render a compact CSV export.
ql --format csv "SELECT name, file, line FROM functions ORDER BY file, line LIMIT 50" .- Find structurally similar functions (code clones).
ql "SELECT name_a, file_a, name_b, file_b, combined_score FROM similarities ORDER BY combined_score DESC LIMIT 20" .- Find functions similar to a specific one.
ql "SELECT name_b, file_b, combined_score FROM similarities WHERE name_a = 'parse_config' ORDER BY combined_score DESC" .- Find functions with similar call patterns.
ql "SELECT s.name_a, s.name_b, s.behavioral_score FROM similarities s WHERE s.behavioral_score > 0.8 ORDER BY s.behavioral_score DESC" .- Inspect structural fingerprint of a function.
ql "SELECT name, file, complexity, nesting_depth, branch_count, loop_count, call_count FROM fn_fingerprints ORDER BY complexity DESC LIMIT 20" .ql/
├── crates/
│ ├── ql-ast/ AST bridge, Tree-sitter walk, schema mapper
│ ├── ql-adapters/ Tree-sitter adapter implementations per language
│ ├── ql-core/ Query engine, SQL parser, planner, DuckDB execution
│ └── ql-cli/ CLI binary — arg parsing, output formatting, watch mode
└── extension/ VS Code extension (TypeScript)
Single binary. No subprocess protocol. Rust CLI only.
- Shared row types and
TableBatch - Language adapter trait and Tree-sitter walk path
- Go, Rust, TypeScript, and Python adapter support
- DuckDB-backed in-memory schema with multi-table ingest
- Hand-written SQL parser (SELECT, FROM, JOIN, WHERE, ORDER BY, LIMIT, operators)
- Planner maps SQL AST to DuckDB execution
- CLI with table/JSON/CSV output and watch mode
- VS Code extension sidebar for running queries and opening rows
- Structural and behavioral code similarity via function fingerprints and call patterns
cargo test
cargo build --bin qlv1 targets Linux and macOS. No AI, no remote repositories, no type-resolution-heavy semantic analysis, no plugin system.
- add *.ext search in query
- add line:col in table in cmd
- better UI
- cross-platform