Skip to content

Commit 4311065

Browse files
committed
fix(@angular/cli): correct query in find_examples to prevent runtime error
This commit fixes a runtime error in the `find_examples` tool that occurred when filtering examples. The error `no such column: experimental` was caused by an incorrect SQL query that attempted to access a column on the FTS virtual table (`examples_fts`) that only exists on the main content table (`examples`). The fix refactors the database query to use a `JOIN` between the `examples` and `examples_fts` tables. This allows the `WHERE` clause to correctly filter on the `experimental` column from the main table while still leveraging the full-text search capabilities of the virtual table.
1 parent 406315d commit 4311065

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/angular/cli/src/commands/mcp/tools/examples.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,11 @@ function queryDatabase(db: DatabaseSync, input: FindExampleInput) {
339339
// Build the query dynamically
340340
const params: SQLInputValue[] = [];
341341
let sql =
342-
'SELECT title, summary, keywords, required_packages, related_concepts, related_tools, content, ' +
342+
`SELECT e.title, e.summary, e.keywords, e.required_packages, e.related_concepts, e.related_tools, e.content, ` +
343343
// The `snippet` function generates a contextual snippet of the matched text.
344344
// Column 6 is the `content` column. We highlight matches with asterisks and limit the snippet size.
345345
"snippet(examples_fts, 6, '**', '**', '...', 15) AS snippet " +
346-
'FROM examples_fts';
346+
'FROM examples e JOIN examples_fts ON e.id = examples_fts.rowid';
347347
const whereClauses = [];
348348

349349
// FTS query
@@ -356,7 +356,7 @@ function queryDatabase(db: DatabaseSync, input: FindExampleInput) {
356356
const addJsonFilter = (column: string, values: string[] | undefined) => {
357357
if (values?.length) {
358358
for (const value of values) {
359-
whereClauses.push(`${column} LIKE ?`);
359+
whereClauses.push(`e.${column} LIKE ?`);
360360
params.push(`%"${value}"%`);
361361
}
362362
}
@@ -367,7 +367,7 @@ function queryDatabase(db: DatabaseSync, input: FindExampleInput) {
367367
addJsonFilter('related_concepts', related_concepts);
368368

369369
if (!includeExperimental) {
370-
whereClauses.push('experimental = 0');
370+
whereClauses.push('e.experimental = 0');
371371
}
372372

373373
if (whereClauses.length > 0) {

0 commit comments

Comments
 (0)