Code
Detect languages, count lines and functions, and extract symbols, imports and comments from source code
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/code/index.md to help me query Code with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
List the function symbols and their line spans in a Rust source string.
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT name, start_line, end_line FROM code.main.symbols('fn a() {}
fn b() {}
', 'rust') WHERE kind = 'function' ORDER BY start_line
| name | start_line | end_line |
|---|---|---|
| a | 1 | 1 |
| b | 2 | 2 |
Quick start
Choose where to run Code, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the release directly
Downloads the latest release for your platform and caches it locally.
ATTACH 'code' AS code (
TYPE vgi,
LOCATION 'github-auto://Query-farm/vgi-code'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'code' AS code (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-code:0.5.0'
);
3. Run a query
SELECT name, start_line, end_line FROM code.main.symbols('fn a() {}
fn b() {}
', 'rust') WHERE kind = 'function' ORDER BY start_line
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'code' AS code
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT name, start_line, end_line FROM code.main.symbols('fn a() {}
fn b() {}
', 'rust') WHERE kind = 'function' ORDER BY start_line
Query Farm operates Code for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use code as the catalog alias for the query below.
4. Run a query
SELECT name, start_line, end_line FROM code.main.symbols('fn a() {}
fn b() {}
', 'rust') WHERE kind = 'function' ORDER BY start_line
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the release directly
Uses the verified release each time you attach the connector.
ATTACH 'code' AS code (
TYPE vgi,
LOCATION 'github-auto://Query-farm/[email protected]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'code' AS code (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-code:0.5.0'
);
Overview
Source-code structure for DuckDB: tree-sitter symbols, imports, comments, strings, line counts and arbitrary tree-sitter queries.

Parse, search, and measure source code directly in SQL: extract symbols, imports, comments, and string literals, count physical lines and function definitions, and run arbitrary tree-sitter queries across nine programming languages — all over Apache Arrow with no language server, no checkout, and no external services.
The code worker turns DuckDB into a lightweight code-intelligence engine for developers, data and platform engineers, and security or research teams who need to treat large codebases as queryable data. Point it at source held in any DuckDB table or file and get structured facts back as ordinary rows and columns. Because everything is just SQL, you can join code structure against commits, issues, ownership, or CVE data and compute metrics over an entire repository in a single query.
Parsing is powered by tree-sitter, the fast, incremental, error-tolerant parsing library used by editors and code-search tools such as Neovim, Zed, and GitHub. Each call builds a concrete syntax tree and runs curated per-language tree-sitter queries, so extraction stays accurate even on incomplete or malformed input (garbage in yields empty results, never a crash). Supported languages are rust, python, javascript, typescript, go, java, c, cpp, and json. See the official tree-sitter documentation and the tree-sitter source on GitHub for grammar and query details.
Key concepts
Everything is exposed as ordinary SQL: scalar functions take a per-row source string (and, where parsing is needed, a language id) and return a value or a VARCHAR[] array; table functions take a constant source and return a result set you can join and aggregate. Language ids are lowercase (rust, python, go, …) and parsing is best-effort — malformed or truncated input yields empty results rather than an error, while an unknown language or a bad tree-sitter query is reported clearly.
When to reach for it
Use the code worker whenever you want to treat source as data instead of text: build codebase metrics dashboards (size, complexity, function density), audit dependencies and import graphs, mine comments and TODOs, scan string literals for secrets, URLs, or missing license headers, and run structural code search with your own tree-sitter queries. Because the answers come back as rows, you can join them against commits, ownership, issues, or CVE data and compute over an entire repository in one query.
Catalog
Everything code exposes once attached — read straight from the worker's
released build.
main 1 table · 10 functions
Source-code structure functions: language detection, line/function counts, import/comment/string extraction, tree-sitter queries and symbol listing.
Schema examples (9)
Detect a file's language from its extension.
SELECT code.main.language_of('src/main.rs');
Count the lines of code (excluding blank and comment lines) in a Rust source string.
SELECT code.main.loc('fn a() {}
// note
fn b() {}
', 'rust');
Count the function definitions in a Python source string.
SELECT code.main.count_functions('def a(): pass
def b(): pass
', 'python');
Extract each Python import statement, one per row.
SELECT UNNEST(code.main.extract_imports('import os
import sys
', 'python')) AS import;
5 more examples
List the function symbols and their line spans in a Rust source string.
SELECT name, start_line, end_line FROM code.main.symbols('fn a() {}
fn b() {}
', 'rust') WHERE kind = 'function' ORDER BY start_line;
| name | start_line | end_line |
|---|---|---|
| a | 1 | 1 |
| b | 2 | 2 |
List every language id the worker can parse.
SELECT language FROM code.main.supported_languages ORDER BY language;
Per-file code metrics over a table of (path, source) rows: detect each file's language from its path with language_of and pass it to loc, count_functions and extract_imports.
SELECT f.path, code.main.language_of(f.path) AS lang, code.main.loc(f.src, code.main.language_of(f.path)) AS code_lines, code.main.count_functions(f.src, code.main.language_of(f.path)) AS functions, len(code.main.extract_imports(f.src, code.main.language_of(f.path))) AS imports FROM (VALUES ('src/lib.rs', 'use std::fmt;
// helper
fn a() {}
fn b() {}
'), ('app/main.py', 'import os
def run():
pass
')) AS f(path, src) ORDER BY f.path;
Build a call graph: join the function spans from symbols with the call sites captured by ts_nodes to list which function calls which.
SELECT s.name AS caller, c.text AS callee, c.start_line FROM code.main.symbols('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust') AS s JOIN code.main.ts_nodes('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust', '(call_expression function: (identifier) @callee)') AS c ON c.start_line BETWEEN s.start_line AND s.end_line WHERE s.kind = 'function' ORDER BY c.start_line;
Per-function metrics: capture each Rust function's source with ts_nodes, then read its name with ts_query and measure it with loc and extract_comments.
SELECT code.main.ts_query(n.text, 'rust', '(function_item name: (identifier) @n)')[1] AS function_name, code.main.loc(n.text, 'rust') AS code_lines, len(code.main.extract_comments(n.text, 'rust')) AS comments FROM code.main.ts_nodes('fn small() {}
fn add(a: i32, b: i32) -> i32 {
// sum the inputs
a + b
}
', 'rust', '(function_item) @f') AS n ORDER BY n.seq;
supported_languages
The language ids this worker can parse, one per row (the accepted language argument values for the other functions).
List every language id the worker can parse.
SELECT language FROM code.main.supported_languages ORDER BY language;
Check whether a language is supported.
SELECT count(*) > 0 AS supported
FROM code.main.supported_languages
WHERE language = 'rust';
SELECT language FROM code.main.supported_languages() ORDER BY language;
9 more examples
SELECT code.main.language_of('src/main.rs') AS lang;
SELECT code.main.count_lines('fn a() {}
fn b() {}
') AS lines;
SELECT code.main.loc('fn a() {}
// note
fn b() {}
', 'rust') AS loc;
SELECT code.main.count_functions('def a(): pass
def b(): pass
', 'python') AS fns;
SELECT code.main.extract_imports('import os
import sys
', 'python') AS imports;
SELECT kind, name, start_line FROM code.main.symbols('fn alpha() {}
fn beta() {}
', 'rust') ORDER BY start_line;
SELECT capture, text FROM code.main.ts_nodes('fn alpha() {}
', 'rust', '(function_item name: (identifier) @n)') ORDER BY seq;
SELECT code.main.extract_comments('// header
fn a() {}
', 'rust') AS comments;
SELECT s.name AS caller, c.text AS callee, c.start_line FROM code.main.symbols('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust') AS s JOIN code.main.ts_nodes('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust', '(call_expression function: (identifier) @callee)') AS c ON c.start_line BETWEEN s.start_line AND s.end_line WHERE s.kind = 'function' ORDER BY c.start_line;
count_functions (source VARCHAR, language VARCHAR)
Number of function/method definitions for the given language
Count function/method definitions in the source (→ 2).
SELECT code.main.count_functions('def a(): pass
def b(): pass
', 'python');
count_lines (source VARCHAR)
Total number of physical lines in the source (NULL → NULL)
Count the physical lines in a source string (→ 2).
SELECT code.main.count_lines('fn a() {}
fn b() {}
');
extract_comments (source VARCHAR, language VARCHAR)
Comment texts in the source, as a VARCHAR[]
Collect the comment texts from Rust source as a VARCHAR[].
SELECT code.main.extract_comments('// header
fn a() {}
', 'rust');
extract_imports (source VARCHAR, language VARCHAR)
Import / use / require statements in the source, as a VARCHAR[]
Extract each import statement from Python source, one per row.
SELECT UNNEST(code.main.extract_imports('import os
import sys
', 'python'));
extract_strings (source VARCHAR, language VARCHAR)
String-literal texts in the source, as a VARCHAR[]
Collect the string-literal texts from Rust source as a VARCHAR[].
SELECT code.main.extract_strings('let s = "hello";
', 'rust');
language_of (filename VARCHAR)
Infer the source language from a filename's extension (NULL if unknown)
Detect the source language of a file from its extension (→ 'rust').
SELECT code.main.language_of('src/main.rs');
Per-file code metrics over a table of (path, source) rows: detect each file's language from its path with language_of and pass it to loc, count_functions and extract_imports.
SELECT f.path, code.main.language_of(f.path) AS lang, code.main.loc(f.src, code.main.language_of(f.path)) AS code_lines, code.main.count_functions(f.src, code.main.language_of(f.path)) AS functions, len(code.main.extract_imports(f.src, code.main.language_of(f.path))) AS imports FROM (VALUES ('src/lib.rs', 'use std::fmt;
// helper
fn a() {}
fn b() {}
'), ('app/main.py', 'import os
def run():
pass
')) AS f(path, src) ORDER BY f.path;
loc (source VARCHAR, language VARCHAR)
Lines of code: non-blank, non-comment lines for the given language
Count lines of code, excluding blank and comment lines (→ 2).
SELECT code.main.loc('fn a() {}
// note
fn b() {}
', 'rust');
ts_query (source VARCHAR, language VARCHAR, query VARCHAR)
Run a tree-sitter query over the source and return the captured node texts (VARCHAR[])
Run a tree-sitter query and return captured node texts (here, the two function names).
SELECT code.main.ts_query('fn alpha() {}
fn beta() {}
', 'rust', '(function_item name: (identifier) @n)');
symbols (source VARCHAR, language VARCHAR)
Structural symbols (functions, classes, methods, structs, enums, …) of a source doc
List the function symbols and their line spans in a Rust source string.
SELECT name, start_line, end_line FROM code.main.symbols('fn a() {}
fn b() {}
', 'rust') WHERE kind = 'function' ORDER BY start_line;
| name | start_line | end_line |
|---|---|---|
| a | 1 | 1 |
| b | 2 | 2 |
Count the defined symbols by kind in a Python source string.
SELECT kind, count(*) AS n FROM code.main.symbols('class C:
def m(self): pass
def f(): pass
', 'python') GROUP BY kind ORDER BY kind;
Build a call graph: join the function spans from symbols with the call sites captured by ts_nodes to list which function calls which.
SELECT s.name AS caller, c.text AS callee, c.start_line FROM code.main.symbols('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust') AS s JOIN code.main.ts_nodes('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust', '(call_expression function: (identifier) @callee)') AS c ON c.start_line BETWEEN s.start_line AND s.end_line WHERE s.kind = 'function' ORDER BY c.start_line;
ts_nodes (source VARCHAR, language VARCHAR, query VARCHAR)
Tree-sitter query matches over a source doc as (seq, capture, text, start_line, end_line) rows
Return each tree-sitter capture's name and text in document order.
SELECT capture, text FROM code.main.ts_nodes('fn alpha() {}
fn beta() {}
', 'rust', '(function_item name: (identifier) @n)') ORDER BY seq;
Return just the captured node texts and their line spans.
SELECT text, start_line FROM code.main.ts_nodes('fn alpha() {}
fn beta() {}
', 'rust', '(function_item name: (identifier) @n)') ORDER BY seq;
Per-function metrics: capture each Rust function's source with ts_nodes, then read its name with ts_query and measure it with loc and extract_comments.
SELECT code.main.ts_query(n.text, 'rust', '(function_item name: (identifier) @n)')[1] AS function_name, code.main.loc(n.text, 'rust') AS code_lines, len(code.main.extract_comments(n.text, 'rust')) AS comments FROM code.main.ts_nodes('fn small() {}
fn add(a: i32, b: i32) -> i32 {
// sum the inputs
a + b
}
', 'rust', '(function_item) @f') AS n ORDER BY n.seq;
Try these queries
Detect a file's language from its extension.
SELECT code.main.language_of('src/main.rs')
Uses language_of
Count the lines of code (excluding blank and comment lines) in a Rust source string.
SELECT code.main.loc('fn a() {}
// note
fn b() {}
', 'rust')
Uses loc
Count the function definitions in a Python source string.
SELECT code.main.count_functions('def a(): pass
def b(): pass
', 'python')
Uses count_functions
Extract each Python import statement, one per row.
SELECT UNNEST(code.main.extract_imports('import os
import sys
', 'python')) AS import
Uses extract_imports
List every language id the worker can parse.
SELECT language FROM code.main.supported_languages ORDER BY language
Uses supported_languages
Build a call graph: join the function spans from symbols with the call sites captured by ts_nodes to list which function calls which.
SELECT s.name AS caller, c.text AS callee, c.start_line FROM code.main.symbols('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust') AS s JOIN code.main.ts_nodes('fn main() {
parse();
run();
}
fn run() {
log();
}
', 'rust', '(call_expression function: (identifier) @callee)') AS c ON c.start_line BETWEEN s.start_line AND s.end_line WHERE s.kind = 'function' ORDER BY c.start_line
20 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- Using this worker, how many function definitions are in this Rust source string: 'fn a() {} fn b() {} fn c() {}' ? Return the single integer count.
- Using this worker, list the names of the top-level definitions in this Rust source string: 'fn a() {} struct S {}' . Return just the names, one per row.
- Using this worker, which programming languages can it parse? Return the language ids, one per row.
Code is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
BGP
Developer & networking
Query RouteViews and RIPE RIS MRT archives (RIB snapshots and BGP updates) as SQL rows, with AS-path and community helpers
NetFlow
Developer & networking
Turn captured NetFlow v5/v9, IPFIX, and sFlow v5 datagrams into normalized, queryable flow rows
Perf
Developer & networking
Decode Linux perf.data captures into SQL tables of samples, memory mappings, and event metadata for bulk profile analysis