( tab: Tab, driver?: string, options?: ReconstructQueryOptions, )
| 324 | * instead of appending directly. |
| 325 | */ |
| 326 | export function reconstructTableQuery( |
| 327 | tab: Tab, |
| 328 | driver?: string, |
| 329 | options?: ReconstructQueryOptions, |
| 330 | ): string { |
| 331 | if (!tab.activeTable) { |
| 332 | return tab.query; |
| 333 | } |
| 334 | |
| 335 | const filterClause = |
| 336 | options?.filterOverride !== undefined |
| 337 | ? options.filterOverride |
| 338 | : tab.filterClause; |
| 339 | const sortClause = |
| 340 | options?.sortOverride !== undefined |
| 341 | ? options.sortOverride |
| 342 | : tab.sortClause; |
| 343 | const limitClause = |
| 344 | options?.limitOverride !== undefined |
| 345 | ? options.limitOverride |
| 346 | : tab.limitClause; |
| 347 | |
| 348 | const filter = filterClause ? `WHERE ${filterClause}` : ""; |
| 349 | const sort = sortClause ? `ORDER BY ${sortClause}` : ""; |
| 350 | const quotedTable = quoteTableRef(tab.activeTable, driver, tab.schema); |
| 351 | |
| 352 | let baseQuery = `SELECT * FROM ${quotedTable} ${filter} ${sort}`.trim(); |
| 353 | |
| 354 | if (limitClause && limitClause > 0) { |
| 355 | if (options?.wrapLimitSubquery) { |
| 356 | baseQuery = `SELECT * FROM (${baseQuery} LIMIT ${limitClause}) AS limited_subset`; |
| 357 | } else { |
| 358 | baseQuery = `${baseQuery} LIMIT ${limitClause}`; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | return baseQuery.replace(/\s+/g, " ").trim(); |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Format an export filename with timestamp and extension |
no test coverage detected