-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathCheckMetadata.ts
More file actions
76 lines (65 loc) · 2.28 KB
/
CheckMetadata.ts
File metadata and controls
76 lines (65 loc) · 2.28 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type { EntityMetadata } from "./EntityMetadata"
import type { NamingStrategyInterface } from "../naming-strategy/NamingStrategyInterface"
import type { CheckMetadataArgs } from "../metadata-args/CheckMetadataArgs"
/**
* Check metadata contains all information about table's check constraints.
*/
export class CheckMetadata {
// ---------------------------------------------------------------------
// Public Properties
// ---------------------------------------------------------------------
/**
* Entity metadata of the class to which this check constraint is applied.
*/
entityMetadata: EntityMetadata
/**
* Target class to which metadata is applied.
*/
target?: Function | string
/**
* Check expression.
*/
expression: string
/**
* User specified check constraint name.
*/
givenName?: string
/**
* Final check constraint name.
* If check constraint name was given by a user then it stores normalized (by naming strategy) givenName.
* If check constraint name was not given then its generated.
*/
name: string
// ---------------------------------------------------------------------
// Constructor
// ---------------------------------------------------------------------
constructor(options: {
entityMetadata: EntityMetadata
args?: CheckMetadataArgs
}) {
this.entityMetadata = options.entityMetadata
if (options.args) {
this.target = options.args.target
this.expression = options.args.expression
this.givenName = options.args.name
}
}
// ---------------------------------------------------------------------
// Public Build Methods
// ---------------------------------------------------------------------
/**
* Builds some depend check constraint properties.
* Must be called after all entity metadata's properties map, columns and relations are built.
*
* @param namingStrategy
*/
build(namingStrategy: NamingStrategyInterface): this {
this.name =
this.givenName ??
namingStrategy.checkConstraintName(
this.entityMetadata.tableName,
this.expression,
)
return this
}
}