Files
smartclickhouse/ts/smartclickhouse.classes.resultset.ts

45 lines
1002 B
TypeScript

import * as plugins from './smartclickhouse.plugins.js';
export class ClickhouseResultSet<T> {
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<U>(fn: (row: T) => U): U[] {
return this.rows.map(fn);
}
public filter(fn: (row: T) => boolean): ClickhouseResultSet<T> {
return new ClickhouseResultSet<T>(this.rows.filter(fn));
}
public toObservable(): plugins.smartrx.rxjs.Observable<T> {
return new plugins.smartrx.rxjs.Observable<T>((observer) => {
for (const row of this.rows) {
observer.next(row);
}
observer.complete();
});
}
}