* 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,
)
| 2038 | * reading of a negative limit (no limit) this follows. |
| 2039 | */ |
| 2040 | private readFilteredPage<T extends { name: string; file_path: string }>( |
| 2041 | sql: string, |
| 2042 | params: (string | number)[], |
| 2043 | filters: FieldFilters, |
| 2044 | limit: number, |
| 2045 | offset: number, |
| 2046 | ): T[] { |
| 2047 | const page: T[] = []; |
| 2048 | if (limit === 0) return page; |
| 2049 | let skipped = 0; |
| 2050 | for (const row of this.db.prepare(sql).iterate(...params) as IterableIterator<T>) { |
| 2051 | if (!passesFieldFilters(row.name, row.file_path, filters)) continue; |
| 2052 | if (skipped < offset) { |
| 2053 | skipped++; |
| 2054 | continue; |
| 2055 | } |
| 2056 | page.push(row); |
| 2057 | if (page.length === limit) break; |
| 2058 | } |
| 2059 | return page; |
| 2060 | } |
| 2061 | |
| 2062 | /** |
| 2063 | * Match-everything path used when the user supplied only field |
no test coverage detected