|
1 | 1 | import { WhereBuilder } from "./where-builder"; |
2 | 2 | import { ColumnsValuesBuilder } from "../core/columns-values-builder"; |
3 | 3 | import { ColumnsCompiled } from "../core/columns-compiled"; |
4 | | -import { QueryCompiled } from "../core/query-compiled"; |
5 | | -import { CrudCompiled } from "../core/crud-compiled"; |
6 | | -import { WhereCompiled } from "./where-compiled"; |
7 | 4 | import { MapperTable } from "../mapper-table"; |
| 5 | +import { SqlBaseBuilder } from "./sql-base-builder"; |
| 6 | +import { QueryCompiled } from "../core/query-compiled"; |
8 | 7 |
|
9 | | -let NEXT_VALUE_ALIAS: number = 0; |
| 8 | +// let NEXT_VALUE_ALIAS: number = 0; |
10 | 9 |
|
11 | | -export abstract class CrudBaseBuilder<T, TColumnsBuilder extends ColumnsValuesBuilder<T, TColumnsBuilder>> { |
| 10 | +export abstract class CrudBaseBuilder< |
| 11 | + T, |
| 12 | + TColumnsBuilder extends ColumnsValuesBuilder<T, TColumnsBuilder> |
| 13 | + > extends SqlBaseBuilder<T> { |
12 | 14 |
|
13 | | - protected _tablename: string; |
| 15 | + // protected _tablename: string; |
14 | 16 |
|
15 | | - private _columnsCompiled: ColumnsCompiled = { columns: [], params: [], keyColumns: [] }; |
16 | | - private _whereCompiled: WhereCompiled = { where: "", params: [] }; |
| 17 | + private _columnsCompiled: ColumnsCompiled = { |
| 18 | + columns: [], |
| 19 | + params: [], |
| 20 | + keyColumns: [] |
| 21 | + }; |
| 22 | + // private _whereCompiled: WhereCompiled = { where: "", params: [] }; |
17 | 23 |
|
18 | 24 | constructor( |
19 | | - protected readonly _typeT: new () => T, |
20 | | - // protected metadata: MetadataTable<T>, |
21 | | - protected mapperTable: MapperTable, |
22 | | - protected readonly _alias: string = void 0, |
| 25 | + typeT: new () => T, |
| 26 | + mapperTable: MapperTable, |
| 27 | + alias: string = void 0, |
23 | 28 | ) { |
24 | | - this._tablename = _typeT.name; |
25 | | - if (!this._alias) { |
26 | | - this._alias = this.createUniqueAlias(this.defaultAlias(_typeT)); |
27 | | - } |
| 29 | + super(typeT, mapperTable, alias); |
| 30 | + // this._tablename = _typeT ? _typeT.name : mapperTable.tableName; |
| 31 | + // if (!this._alias) { |
| 32 | + // this._alias = this.createUniqueAlias(this.defaultAlias(this._tablename)); |
| 33 | + // } |
28 | 34 | } |
29 | 35 |
|
30 | | - // public getMetadata(): MetadataTable<T> { |
31 | | - // return this.metadata; |
| 36 | + // public getMapper(): MapperTable { |
| 37 | + // return this.mapperTable; |
32 | 38 | // } |
33 | 39 |
|
34 | | - public getMapper(): MapperTable { |
35 | | - return this.mapperTable; |
36 | | - } |
37 | | - |
38 | | - public hasAlias(alias: string): boolean { |
39 | | - if (this._alias === alias) { |
40 | | - return true; |
41 | | - } |
42 | | - return false; |
43 | | - } |
| 40 | + // public hasAlias(alias: string): boolean { |
| 41 | + // if (this._alias === alias) { |
| 42 | + // return true; |
| 43 | + // } |
| 44 | + // return false; |
| 45 | + // } |
44 | 46 |
|
45 | 47 | public compile(): QueryCompiled { |
46 | 48 | const compiledBase = this.buildBase(); |
47 | 49 | return { |
48 | | - params: compiledBase.params.concat(this._whereCompiled.params), |
49 | | - query: `${compiledBase.sql}${this._whereCompiled.where}`, |
| 50 | + params: compiledBase.params.concat(this.whereCompiled.params), |
| 51 | + query: `${compiledBase.query}${this.whereCompiled.where}`, |
50 | 52 | }; |
51 | 53 | } |
| 54 | + // public compile(): QueryCompiled { |
| 55 | + // const compiledBase = this.buildBase(); |
| 56 | + // return { |
| 57 | + // params: compiledBase.params.concat(this._whereCompiled.params), |
| 58 | + // query: `${compiledBase.sql}${this._whereCompiled.where}`, |
| 59 | + // }; |
| 60 | + // } |
52 | 61 |
|
53 | 62 | protected getColumnsCompiled(): ColumnsCompiled { |
54 | 63 | if (!this._columnsCompiled.columns.length) { |
@@ -77,32 +86,32 @@ export abstract class CrudBaseBuilder<T, TColumnsBuilder extends ColumnsValuesBu |
77 | 86 | return instanceReturn; |
78 | 87 | } |
79 | 88 |
|
80 | | - protected abstract buildBase(): CrudCompiled; |
| 89 | + // protected abstract buildBase(): CrudCompiled; |
81 | 90 |
|
82 | 91 | protected abstract setDefaultColumns(): void; |
83 | 92 |
|
84 | 93 | public abstract getModel(): T; |
85 | 94 |
|
86 | | - private compileWhere(compiled: WhereCompiled) { |
87 | | - if (compiled.where.length) { |
88 | | - this._whereCompiled.where += `${(this._whereCompiled.where.length ? " AND " : " WHERE ")}${compiled.where}`; |
89 | | - this._whereCompiled.params = this._whereCompiled.params.concat(compiled.params); |
90 | | - } |
91 | | - } |
| 95 | + // private compileWhere(compiled: WhereCompiled) { |
| 96 | + // if (compiled.where.length) { |
| 97 | + // this._whereCompiled.where += `${(this._whereCompiled.where.length ? " AND " : " WHERE ")}${compiled.where}`; |
| 98 | + // this._whereCompiled.params = this._whereCompiled.params.concat(compiled.params); |
| 99 | + // } |
| 100 | + // } |
92 | 101 |
|
93 | | - private defaultAlias(typeT: new () => T) { |
94 | | - if (typeT.name.length > 3) { |
95 | | - return typeT.name.substring(0, 3); |
96 | | - } |
97 | | - return typeT.name; |
98 | | - } |
| 102 | + // private defaultAlias(tableName: string) { |
| 103 | + // if (tableName.length > 3) { |
| 104 | + // return tableName.substring(0, 3); |
| 105 | + // } |
| 106 | + // return tableName; |
| 107 | + // } |
99 | 108 |
|
100 | | - private createUniqueAlias(aliasProposed: string): string { |
101 | | - if (this.hasAlias(aliasProposed)) { |
102 | | - return this.createUniqueAlias(`${aliasProposed}${NEXT_VALUE_ALIAS++}`); |
103 | | - } |
104 | | - return aliasProposed; |
105 | | - } |
| 109 | + // private createUniqueAlias(aliasProposed: string): string { |
| 110 | + // if (this.hasAlias(aliasProposed)) { |
| 111 | + // return this.createUniqueAlias(`${aliasProposed}${NEXT_VALUE_ALIAS++}`); |
| 112 | + // } |
| 113 | + // return aliasProposed; |
| 114 | + // } |
106 | 115 |
|
107 | 116 | private compileColumns(compiled: ColumnsCompiled) { |
108 | 117 | if (compiled.columns.length) { |
|
0 commit comments