mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
refactoring query builder
This commit is contained in:
parent
92411f8039
commit
8d9083bbb9
@ -37,9 +37,6 @@ import {RelationQueryBuilder} from "./RelationQueryBuilder";
|
||||
// .loadAndMap("post.categories", "post.categories", qb => ...)
|
||||
// .loadAndMap("post.categories", Category, qb => ...)
|
||||
|
||||
// todo: implement streaming
|
||||
// .stream(): ReadStream
|
||||
|
||||
/**
|
||||
* Allows to build complex sql queries in a fashion way and execute those queries.
|
||||
*/
|
||||
@ -159,34 +156,6 @@ export abstract class QueryBuilder<Entity> {
|
||||
return new SelectQueryBuilderCls(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new selection to the SELECT query.
|
||||
*/
|
||||
addSelect(selection: string, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
||||
|
||||
/**
|
||||
* Adds new selection to the SELECT query.
|
||||
*/
|
||||
addSelect(selection: string[]): SelectQueryBuilder<Entity>;
|
||||
|
||||
/**
|
||||
* Adds new selection to the SELECT query.
|
||||
*/
|
||||
addSelect(selection: string|string[], selectionAliasName?: string): SelectQueryBuilder<Entity> {
|
||||
if (selection instanceof Array) {
|
||||
this.expressionMap.selects = this.expressionMap.selects.concat(selection.map(selection => ({ selection: selection })));
|
||||
} else {
|
||||
this.expressionMap.selects.push({ selection: selection, aliasName: selectionAliasName });
|
||||
}
|
||||
|
||||
// loading it dynamically because of circular issue
|
||||
const SelectQueryBuilderCls = require("./SelectQueryBuilder").SelectQueryBuilder;
|
||||
if (this instanceof SelectQueryBuilderCls)
|
||||
return this as any;
|
||||
|
||||
return new SelectQueryBuilderCls(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates INSERT query.
|
||||
*/
|
||||
@ -321,6 +290,14 @@ export abstract class QueryBuilder<Entity> {
|
||||
return sql.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints sql to stdout using console.log.
|
||||
*/
|
||||
printSql(): this {
|
||||
console.log(this.getSql());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets generated sql that will be executed.
|
||||
* Parameters in the query are escaped for the currently used driver.
|
||||
|
||||
@ -28,6 +28,29 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> {
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Adds new selection to the SELECT query.
|
||||
*/
|
||||
addSelect(selection: string, selectionAliasName?: string): this;
|
||||
|
||||
/**
|
||||
* Adds new selection to the SELECT query.
|
||||
*/
|
||||
addSelect(selection: string[]): this;
|
||||
|
||||
/**
|
||||
* Adds new selection to the SELECT query.
|
||||
*/
|
||||
addSelect(selection: string|string[], selectionAliasName?: string): this {
|
||||
if (selection instanceof Array) {
|
||||
this.expressionMap.selects = this.expressionMap.selects.concat(selection.map(selection => ({ selection: selection })));
|
||||
} else {
|
||||
this.expressionMap.selects.push({ selection: selection, aliasName: selectionAliasName });
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies FROM which entity's table select/update/delete will be executed.
|
||||
* Also sets a main string alias of the selection data.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user