import {QueryRow} from '../../types' import {Builder} from '../Builder' import {Connection} from '../../connection/Connection' import {AbstractResultIterable} from './AbstractResultIterable' import {Collection} from '../../../util' /** * Implementation of AbstractResultIterable that yields simple QueryRow instances (objects). */ export class ResultIterable extends AbstractResultIterable { constructor( public readonly builder: Builder, public readonly connection: Connection, ) { super(builder, connection) } public get selectSQL(): string { return this.connection.dialect().renderSelect(this.builder) } async at(i: number): Promise { const query = this.connection.dialect().renderRangedSelect(this.selectSQL, i, i + 1) return (await this.connection.query(query)).rows.first() } async range(start: number, end: number): Promise> { const query = this.connection.dialect().renderRangedSelect(this.selectSQL, start, end) return (await this.connection.query(query)).rows } async count(): Promise { const query = this.connection.dialect().renderCount(this.selectSQL) const result = (await this.connection.query(query)).rows.first() return result?.extollo_render_count ?? 0 } async all(): Promise> { const result = await this.connection.query(this.selectSQL) return result.rows } clone(): ResultIterable { return new ResultIterable(this.builder, this.connection) } }