Skip to content

Commit

Permalink
sqlite: ORDER BY rank in FTS query
Browse files Browse the repository at this point in the history
  • Loading branch information
wsporto committed Jul 25, 2024
1 parent 4e541bf commit acf706d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sqlite-query-analyzer/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function traverse_select_stmt(
} else {
traverse_expr(expr, {
...traverseContext,
fromColumns: fromColumns.concat(selectColumns)
fromColumns: mainQueryResult.fromColumns.concat(selectColumns)
});
}
});
Expand Down
61 changes: 60 additions & 1 deletion tests/sqlite/sqlite-parse-select-multiples-tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ describe('sqlite-parse-select-multiples-tables', () => {
assert.deepStrictEqual(actual.right, expected);
});

it('FTS5 - WHERE mytable2_fts match :match', () => {//
it('FTS5 - SELECT t2.*, rank', () => {
const sql = `
SELECT t2.*, rank
FROM mytable2 t2
Expand Down Expand Up @@ -974,4 +974,63 @@ describe('sqlite-parse-select-multiples-tables', () => {
}
assert.deepStrictEqual(actual.right, expected);
});

it('FTS5 - ORDER BY rank', () => {
const sql = `
SELECT *
FROM mytable2 t2
INNER JOIN mytable2_fts fts2 on fts2.id = t2.id
WHERE mytable2_fts match 'one'
ORDER BY rank
`;
const actual = parseSql(sql, sqliteDbSchema);
const expected: SchemaDef = {
sql,
queryType: 'Select',
multipleRowsResult: true,
columns: [
{
columnName: 'id',
type: 'INTEGER',
notNull: true,
table: 't2'
},
{
columnName: 'name',
type: 'TEXT',
notNull: false,
table: 't2'
},
{
columnName: 'descr',
type: 'TEXT',
notNull: false,
table: 't2'
},
{
columnName: 'id',
type: 'INTEGER',
notNull: false, //TODO - should be true: on fts2.id = t2.id
table: 'fts2'
},
{
columnName: 'name',
type: 'any',
notNull: false,
table: 'fts2'
},
{
columnName: 'descr',
type: 'any',
notNull: false,
table: 'fts2'
},
],
parameters: []
};
if (isLeft(actual)) {
assert.fail(`Shouldn't return an error: ${actual.left.description}`);
}
assert.deepStrictEqual(actual.right, expected);
});
});

0 comments on commit acf706d

Please sign in to comment.