/
Alias.ts
48 lines (35 loc) · 1 KB
/
Alias.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {EntityMetadata} from "../metadata/EntityMetadata";
import {ObjectUtils} from "../util/ObjectUtils";
/**
*/
export class Alias {
type: "from"|"select"|"join"|"other"; // todo: make something with "other"
name: string;
/**
* Table on which this alias is applied.
* Used only for aliases which select custom tables.
*/
tablePath?: string;
/**
* If this alias is for sub query.
*/
subQuery?: string;
constructor(alias?: Alias) {
ObjectUtils.assign(this, alias || {});
}
private _metadata?: EntityMetadata;
get target(): Function|string {
return this.metadata.target;
}
get hasMetadata(): boolean {
return !!this._metadata;
}
set metadata(metadata: EntityMetadata) {
this._metadata = metadata;
}
get metadata(): EntityMetadata {
if (!this._metadata)
throw new Error(`Cannot get entity metadata for the given alias "${this.name}"`);
return this._metadata;
}
}