Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import {Model} from "./Model";
|
||||
import {AbstractResultIterable} from "../builder/result/AbstractResultIterable";
|
||||
import {Connection} from "../connection/Connection";
|
||||
import {ModelBuilder} from "./ModelBuilder";
|
||||
import {Container, Instantiable} from "../../di";
|
||||
import {QueryRow} from "../types";
|
||||
import {Collection} from "../../util";
|
||||
import {Model} from './Model'
|
||||
import {AbstractResultIterable} from '../builder/result/AbstractResultIterable'
|
||||
import {Connection} from '../connection/Connection'
|
||||
import {ModelBuilder} from './ModelBuilder'
|
||||
import {Container, Instantiable} from '../../di'
|
||||
import {QueryRow} from '../types'
|
||||
import {Collection} from '../../util'
|
||||
|
||||
/**
|
||||
* Implementation of the result iterable that returns query results as instances of the defined model.
|
||||
@@ -14,14 +14,16 @@ export class ModelResultIterable<T extends Model<T>> extends AbstractResultItera
|
||||
public readonly builder: ModelBuilder<T>,
|
||||
public readonly connection: Connection,
|
||||
/** The model that should be instantiated for each row. */
|
||||
protected readonly ModelClass: Instantiable<T>
|
||||
) { super(builder, connection) }
|
||||
protected readonly ModelClass: Instantiable<T>,
|
||||
) {
|
||||
super(builder, connection)
|
||||
}
|
||||
|
||||
public get selectSQL() {
|
||||
public get selectSQL(): string {
|
||||
return this.connection.dialect().renderSelect(this.builder)
|
||||
}
|
||||
|
||||
async at(i: number) {
|
||||
async at(i: number): Promise<T | undefined> {
|
||||
const query = this.connection.dialect().renderRangedSelect(this.selectSQL, i, i + 1)
|
||||
const row = (await this.connection.query(query)).rows.first()
|
||||
|
||||
@@ -35,7 +37,7 @@ export class ModelResultIterable<T extends Model<T>> extends AbstractResultItera
|
||||
return (await this.connection.query(query)).rows.promiseMap<T>(row => this.inflateRow(row))
|
||||
}
|
||||
|
||||
async count() {
|
||||
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
|
||||
@@ -52,10 +54,11 @@ export class ModelResultIterable<T extends Model<T>> extends AbstractResultItera
|
||||
* @protected
|
||||
*/
|
||||
protected async inflateRow(row: QueryRow): Promise<T> {
|
||||
return Container.getContainer().make<T>(this.ModelClass).assumeFromSource(row)
|
||||
return Container.getContainer().make<T>(this.ModelClass)
|
||||
.assumeFromSource(row)
|
||||
}
|
||||
|
||||
clone() {
|
||||
clone(): ModelResultIterable<T> {
|
||||
return new ModelResultIterable(this.builder, this.connection, this.ModelClass)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user