* One page of the rows `sql` returns that pass `filters`: up to `limit` of * them, after skipping the first `offset` that pass, so a source's limit and * offset count only what the filters let through. `sql` has no LIMIT or * OFFSET of its own. Its rows are streamed and the read stops once
(
sql: string,
params: (string | number)[],
filters: FieldFilters,
limit: number,
offset: number,
)
| 2022 | * reading of a negative limit (no limit) this follows. |
| 2023 | */ |
| 2024 | private readFilteredPage<T extends { name: string; file_path: string }>( |
| 2025 | sql: string, |
| 2026 | params: (string | number)[], |
| 2027 | filters: FieldFilters, |
| 2028 | limit: number, |
| 2029 | offset: number, |
| 2030 | ): T[] { |
| 2031 | const page: T[] = []; |
| 2032 | if (limit === 0) return page; |
| 2033 | let skipped = 0; |
| 2034 | for (const row of this.db.prepare(sql).iterate(...params) as IterableIterator<T>) { |
| 2035 | if (!passesFieldFilters(row.name, row.file_path, filters)) continue; |
| 2036 | if (skipped < offset) { |
| 2037 | skipped++; |
| 2038 | continue; |
| 2039 | } |
| 2040 | page.push(row); |
| 2041 | if (page.length === limit) break; |
| 2042 | } |
| 2043 | return page; |
| 2044 | } |
| 2045 | |
| 2046 | /** |
| 2047 | * Match-everything path used when the user supplied only field |
no test coverage detected