-
-
Notifications
You must be signed in to change notification settings - Fork 496
/
Platform.ts
135 lines (104 loc) · 3.21 KB
/
Platform.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { EntityRepository } from '../entity';
import { NamingStrategy, UnderscoreNamingStrategy } from '../naming-strategy';
import { Constructor, Dictionary, EntityProperty, IPrimaryKey, Primary, ISchemaGenerator } from '../typings';
import { ExceptionConverter } from './ExceptionConverter';
import { EntityManager } from '../EntityManager';
export abstract class Platform {
protected readonly exceptionConverter = new ExceptionConverter();
usesPivotTable(): boolean {
return false;
}
supportsTransactions(): boolean {
return true;
}
usesImplicitTransactions(): boolean {
return true;
}
getNamingStrategy(): { new(): NamingStrategy } {
return UnderscoreNamingStrategy;
}
usesReturningStatement(): boolean {
return false;
}
usesCascadeStatement(): boolean {
return false;
}
getSchemaHelper(): { getTypeDefinition(prop: EntityProperty, types?: Dictionary<string[]>, lengths?: Dictionary<number>, allowZero?: boolean): string } | undefined {
return undefined;
}
requiresNullableForAlteringColumn() {
return false;
}
allowsMultiInsert() {
return true;
}
/**
* Normalizes primary key wrapper to scalar value (e.g. mongodb's ObjectId to string)
*/
normalizePrimaryKey<T extends number | string = number | string>(data: Primary<T> | IPrimaryKey): T {
return data as T;
}
/**
* Converts scalar primary key representation to native driver wrapper (e.g. string to mongodb's ObjectId)
*/
denormalizePrimaryKey(data: IPrimaryKey): IPrimaryKey {
return data;
}
/**
* Used when serializing via toObject and toJSON methods, allows to use different PK field name (like `id` instead of `_id`)
*/
getSerializedPrimaryKeyField(field: string): string {
return field;
}
/**
* Returns the SQL specific for the platform to get the current timestamp
*/
getCurrentTimestampSQL(length: number): string {
return 'current_timestamp' + (length ? `(${length})` : '');
}
getDateTypeDeclarationSQL(length: number): string {
return 'date' + (length ? `(${length})` : '');
}
getTimeTypeDeclarationSQL(length: number): string {
return 'time' + (length ? `(${length})` : '');
}
getRegExpOperator(): string {
return 'regexp';
}
isBigIntProperty(prop: EntityProperty): boolean {
return prop.columnTypes && prop.columnTypes[0] === 'bigint';
}
getBigIntTypeDeclarationSQL(): string {
return 'bigint';
}
getArrayDeclarationSQL(): string {
return 'text';
}
marshallArray(values: string[]): string {
return values.join(',');
}
unmarshallArray(value: string): string[] {
return value.split(',') as string[];
}
getBlobDeclarationSQL(): string {
return 'blob';
}
getJsonDeclarationSQL(): string {
return 'json';
}
convertsJsonAutomatically(marshall = false): boolean {
return !marshall;
}
getRepositoryClass<T>(): Constructor<EntityRepository<T>> {
return EntityRepository;
}
getDefaultCharset(): string {
return 'utf8';
}
getExceptionConverter(): ExceptionConverter {
return this.exceptionConverter;
}
getSchemaGenerator(em: EntityManager): ISchemaGenerator {
throw new Error(`${this.constructor.name} does not use a schema generator`);
}
}