(sql: string, limit: number, offset: number)
| 35 | * @returns Modified SQL query with pagination added |
| 36 | */ |
| 37 | export function addPaginationToQuery(sql: string, limit: number, offset: number): string { |
| 38 | const cleanedSQL = cleanSqlQuery(sql); |
| 39 | const noSemicolon = cleanedSQL.replace(';', ''); |
| 40 | |
| 41 | // Only add LIMIT if not already present |
| 42 | if (!noSemicolon.toUpperCase().includes("LIMIT")) { |
| 43 | return `${noSemicolon} LIMIT ${limit} OFFSET ${offset}`; |
| 44 | } |
| 45 | |
| 46 | return sql; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Creates a COUNT query to get the total number of rows for a SELECT query |
no test coverage detected