Skip to content

Latest commit

 

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ql

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.

Install

From a checkout:

cargo build --release
./target/release/ql --langs

Or install the binary locally:

cargo install --path crates/ql-cli
ql --langs

Example

ql "SELECT name, file, line
    FROM functions
    WHERE complexity > 10
      AND has_test = false" ./src

What It Extracts

Language adapters populate the shared schema:

  • functions
  • calls
  • imports
  • structs
  • variables
  • comments
  • fn_fingerprints — structural metrics per function
  • fn_callsets — callee sets per function
  • similarities — pairwise similarity scores

Schema source lives in schema/tables.json.

Example Queries

All examples assume you run them from a repository root or pass an explicit path as the final argument.

  1. 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" .
  1. List all external calls.
ql "SELECT caller, callee, file, line FROM calls WHERE is_external = true ORDER BY file, line" .
  1. Inspect imports from the standard library.
ql "SELECT module, alias, file, line FROM imports WHERE is_std = true ORDER BY file, line" .
  1. Find public structs and their implemented interfaces.
ql "SELECT name, visibility, implements, file, line FROM structs WHERE visibility = 'public' ORDER BY file, line" .
  1. List mutable variables.
ql "SELECT name, type_hint, scope, file, line FROM variables WHERE is_mutated = true ORDER BY file, line" .
  1. 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" .
  1. Find functions that mention tests.
ql "SELECT name, file, line FROM functions WHERE has_test = true ORDER BY file, line" .
  1. Show functions that return results.
ql "SELECT name, return_type, file, line FROM functions WHERE return_type LIKE '%Result%' ORDER BY file, line" .
  1. Render the same data as JSON.
ql --format json "SELECT name, file, line FROM structs ORDER BY file, line LIMIT 20" .
  1. Render a compact CSV export.
ql --format csv "SELECT name, file, line FROM functions ORDER BY file, line LIMIT 50" .
  1. 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" .
  1. 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" .
  1. 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" .
  1. 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" .

Architecture

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.

Current Status

  • 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

Development

cargo test
cargo build --bin ql

Scope

v1 targets Linux and macOS. No AI, no remote repositories, no type-resolution-heavy semantic analysis, no plugin system.

TODO

  • add *.ext search in query
  • add line:col in table in cmd
  • better UI
  • cross-platform

About

Lets developers query codebases with SQL

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages