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.
lib/src/orm/builder/result/ResultIterable.ts

47 lines
1.6 KiB

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<QueryRow> {
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<QueryRow | undefined> {
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<Collection<QueryRow>> {
const query = this.connection.dialect().renderRangedSelect(this.selectSQL, start, end)
return (await this.connection.query(query)).rows
}
async count(): Promise<number> {
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<Collection<QueryRow>> {
const result = await this.connection.query(this.selectSQL)
return result.rows
}
clone(): ResultIterable {
return new ResultIterable(this.builder, this.connection)
}
}