feat(core): introduce typed ClickHouse table API, query builder, and result handling; enhance HTTP client and add schema evolution, batch inserts and mutations; update docs/tests and bump deps
This commit is contained in:
44
ts/smartclickhouse.classes.resultset.ts
Normal file
44
ts/smartclickhouse.classes.resultset.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user