deno.land / x / pg_mem@2.8.1 / transforms / startswith-filter.ts
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import { _ISelection, IValue, _IIndex, _ITable, getId, _Transaction, _Explainer, _SelectExplanation, Stats } from '../interfaces-private.ts';import { FilterBase } from './transform-base.ts';import { nullIsh } from '../utils.ts';
export class StartsWithFilter<T = any> extends FilterBase<T> {
get index() { return null; }
entropy(t: _Transaction) { return this.onValue.index!.entropy({ type: 'ge', key: [this.startWith], t, }); }
hasItem(item: T, t: _Transaction) { const get = this.onValue.get(item, t); return typeof get === 'string' && get.startsWith(this.startWith); }
constructor(private onValue: IValue<T> , private startWith: string) { super(onValue.origin!); if (onValue.index!.expressions[0].hash !== this.onValue.hash) { throw new Error('Startwith must be the first component of the index'); } }
stats(t: _Transaction): Stats | null { return null; }
*enumerate(t: _Transaction): Iterable<T> { const index = this.onValue.index!; for (const item of index.enumerate({ type: 'ge', key: [this.startWith], t, })) { const got: string = this.onValue.get(item, t); if (nullIsh(got) || !got.startsWith(this.startWith)) { break; } yield item; } }
explain(e: _Explainer): _SelectExplanation { return { id: e.idFor(this), _: 'ineq', entropy: this.entropy(e.transaction), on: this.onValue.index!.explain(e), }; }}
Version Info