import * as plugins from './smartclickhouse.plugins.js'; export class ClickhouseResultSet { public rows: T[]; public rowCount: number; constructor(rows: T[]) { this.rows = rows; this.rowCount = rows.length; } public first(): T | null { return this.rows.length > 0 ? this.rows[0] : null; } public last(): T | null { return this.rows.length > 0 ? this.rows[this.rows.length - 1] : null; } public isEmpty(): boolean { return this.rows.length === 0; } public toArray(): T[] { return this.rows; } public map(fn: (row: T) => U): U[] { return this.rows.map(fn); } public filter(fn: (row: T) => boolean): ClickhouseResultSet { return new ClickhouseResultSet(this.rows.filter(fn)); } public toObservable(): plugins.smartrx.rxjs.Observable { return new plugins.smartrx.rxjs.Observable((observer) => { for (const row of this.rows) { observer.next(row); } observer.complete(); }); } }