You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
962 B
34 lines
962 B
import { Iterable } from '../../../../../lib/src/collection/Iterable.ts'
|
|
import ConnectionExecutable from "../ConnectionExecutable.ts";
|
|
import {QueryRow} from "../../../db/types.ts";
|
|
import {Collection} from "../../../../../lib/src/collection/Collection.ts";
|
|
|
|
export abstract class ResultSet<T> extends Iterable<any> {
|
|
|
|
protected constructor(
|
|
protected executeable: ConnectionExecutable,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
abstract async process_row(row: QueryRow): Promise<T>
|
|
|
|
async at_index(i: number) {
|
|
return this.process_row(await this.executeable.get_row(i))
|
|
}
|
|
|
|
async from_range(start: number, end: number) {
|
|
const results = await this.executeable.get_range(start, end)
|
|
const returns = new Collection<T>()
|
|
for ( const row of results ) {
|
|
returns.push(await this.process_row(row))
|
|
}
|
|
|
|
return returns
|
|
}
|
|
|
|
async count() {
|
|
return this.executeable.count()
|
|
}
|
|
}
|