Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 7b3c654

Browse files
authored
fix: Add or update OFFSET clause in query (#376)
1 parent f71d99a commit 7b3c654

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/hooks/useQueryLogs.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ const { setLogData } = logsStoreReducers;
1717
const { parseQuery } = filterStoreReducers;
1818

1919
const appendOffsetToQuery = (query: string, offset: number) => {
20-
const hasOffset = query.toLowerCase().includes('offset');
21-
return !hasOffset ? query.replace(/offset\s+\d+/i, `OFFSET ${offset}`) : `${query}`;
20+
const offsetRegex = /offset\s+\d+/i;
21+
const limitRegex = /limit\s+\d+/i;
22+
23+
if (offsetRegex.test(query)) {
24+
// Replace the existing OFFSET with the new one
25+
return query.replace(offsetRegex, `OFFSET ${offset}`);
26+
} else {
27+
// Insert OFFSET before LIMIT if OFFSET is not present
28+
return query.replace(limitRegex, `OFFSET ${offset} $&`);
29+
}
2230
};
2331

2432
export const useQueryLogs = () => {

0 commit comments

Comments
 (0)