Skip to content

Commit

Permalink
fix: Add or update OFFSET clause in query (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen5959 authored Nov 27, 2024
1 parent f71d99a commit 7b3c654
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/hooks/useQueryLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ const { setLogData } = logsStoreReducers;
const { parseQuery } = filterStoreReducers;

const appendOffsetToQuery = (query: string, offset: number) => {
const hasOffset = query.toLowerCase().includes('offset');
return !hasOffset ? query.replace(/offset\s+\d+/i, `OFFSET ${offset}`) : `${query}`;
const offsetRegex = /offset\s+\d+/i;
const limitRegex = /limit\s+\d+/i;

if (offsetRegex.test(query)) {
// Replace the existing OFFSET with the new one
return query.replace(offsetRegex, `OFFSET ${offset}`);
} else {
// Insert OFFSET before LIMIT if OFFSET is not present
return query.replace(limitRegex, `OFFSET ${offset} $&`);
}
};

export const useQueryLogs = () => {
Expand Down

0 comments on commit 7b3c654

Please sign in to comment.