Skip to content

Commit 3f3c20b

Browse files
committed
fix: queryToSql dropped OFFSET 0 due to falsy check
Same class of bug as the LIMIT 0 fix — `if (query.offset)` treated offset=0 as falsy and omitted the OFFSET clause from generated SQL. Changed to `if (query.offset !== undefined)`. Added tests for both LIMIT 0 and OFFSET 0 preservation.
1 parent cd254dc commit 3f3c20b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/wasm-engine.integration.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,14 @@ describe("queryToSql", () => {
388388
const sql = queryToSql({ ...base, filters: [{ column: "x", op: "not_between", value: [10, 20] }] });
389389
expect(sql).toContain("NOT BETWEEN 10 AND 20");
390390
});
391+
392+
it("preserves LIMIT 0", () => {
393+
const sql = queryToSql({ ...base, limit: 0 });
394+
expect(sql).toContain("LIMIT 0");
395+
});
396+
397+
it("preserves OFFSET 0", () => {
398+
const sql = queryToSql({ ...base, offset: 0 });
399+
expect(sql).toContain("OFFSET 0");
400+
});
391401
});

src/wasm-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ export function queryToSql(query: QueryDescriptor): string {
10771077
if (query.groupBy?.length) parts.push(`GROUP BY ${query.groupBy.map(quote).join(", ")}`);
10781078
if (query.sortColumn) parts.push(`ORDER BY ${quote(query.sortColumn)} ${query.sortDirection?.toUpperCase() ?? "ASC"}`);
10791079
if (query.limit !== undefined) parts.push(`LIMIT ${query.limit}`);
1080-
if (query.offset) parts.push(`OFFSET ${query.offset}`);
1080+
if (query.offset !== undefined) parts.push(`OFFSET ${query.offset}`);
10811081

10821082
return parts.join(" ");
10831083
}

0 commit comments

Comments
 (0)