database-builder
Version:
Library to assist in creating and maintaining SQL commands.
97 lines (96 loc) • 4.82 kB
TypeScript
import { ExpressionOrColumn, ExpressionProjection, ExpressionQuery, TQuery } from "../core/utils";
import { ColumnRef } from "../core/column-ref";
import { PlanRef } from "../core/plan-ref";
import { ProjectionCompiled } from "./projection-compiled";
import { Projection } from "./enums/projection";
import { ProjectionCase } from "./projection-case";
import { MetadataTable } from "../metadata-table";
import { ProjectionsHelper } from "../core/projections-helper";
import { ProjectionModel } from "./projection-model";
export declare class ProjectionBuilder<T> {
private _typeT;
private _aliasTable;
private _addAliasTableToAlias;
private _getMapper?;
private _projections;
private readonly _projectionsUtils;
constructor(_typeT: new () => T, _aliasTable: string, _addAliasTableToAlias?: boolean, addAliasDefault?: boolean, _getMapper?: (tKey: (new () => any) | string) => MetadataTable<any>);
all(): void;
wildcard(): void;
allByMap(metadata: MetadataTable<T>): void;
proj(): ProjectionsHelper<T>;
ref<TReturn>(expression: ExpressionOrColumn<TReturn, T>, alias?: string): ColumnRef;
plan(value: any): PlanRef;
group(alias: string, ...projections: Array<ExpressionProjection<any, T>>): ProjectionBuilder<T>;
/**
* @deprecated Use `add`
* @param column
* @param alias
*/
column(column: string, alias?: string): ProjectionBuilder<T>;
columns(...expressions: Array<ExpressionOrColumn<any, T>>): ProjectionBuilder<T>;
add<TReturn>(expression: ExpressionQuery<TReturn, T>, alias?: string): ProjectionBuilder<T>;
remove<TReturn>(expression: ExpressionOrColumn<TReturn, T>): ProjectionBuilder<T>;
clean(): ProjectionBuilder<T>;
sum<TReturn>(expression?: ExpressionOrColumn<TReturn, T> | string, alias?: string): ProjectionBuilder<T>;
max<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
min<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
avg<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
/**
* @deprecated use `.avg().round(expression)`
*
* @param {ExpressionOrColumn<T>} expression
* @param {string} [alias]
* @returns {ProjectionBuilder<T>}
* @memberof ProjectionBuilder
*/
avgRound<TReturn>(expression: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
round<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
count<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
/**
* @deprecated use `.count().distinct(expression)`
*
* @param {ExpressionOrColumn<T>} expression
* @param {string} [alias]
* @returns {ProjectionBuilder<T>}
* @memberof ProjectionBuilder
*/
countDistinct<TReturn>(expression: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
cast<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
distinct<TReturn>(expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
/**
* https://www.sqlite.org/lang_expr.html
* CASE {expression} {when} END
* @param caseCallback
* @param expression
* @param alias
*/
case<TReturn>(caseCallback: (caseInstance: ProjectionCase<TReturn, T>) => void, expression?: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
coalesce<TReturn>(expression: ExpressionOrColumn<TReturn, T>, alias?: string): ProjectionBuilder<T>;
coalesceP(projectionCallback: (projection: ProjectionBuilder<T>) => void, defaultValue: any, alias: string): ProjectionBuilder<T>;
/**
* @deprecated use `.proj()`
*
* @param {Projection} projection
* @param {ExpressionOrColumn<T>} expression
* @param {string} [alias=""]
* @param {any[]} [args=[]]
* @returns
* @memberof ProjectionBuilder
*/
projection<TReturn>(projection: Projection, expression: ExpressionOrColumn<TReturn, T>, alias?: string, args?: any[]): ProjectionCompiled;
coalesceBuilder<TReturn>(expression: ExpressionOrColumn<TReturn, T>, defaultValue: any): string;
subQuery(subQuery: TQuery, alias?: string): ProjectionBuilder<T>;
result(): ProjectionModel[];
private selectAllColumns;
private compileCase;
private buildProjectionWithExpression;
private apply;
private applyProjection;
private addAliasTable;
private builderProjection;
private buildArgs;
private defaultAliasAs;
private createProjection;
private buildColumn;
}