midway-model-gen 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +57 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/test.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +161 -0
- package/CONTRIBUTING.md +51 -0
- package/DEVELOPER.md +30 -0
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/USECASES.md +53 -0
- package/bin/typeorm-model-generator +6 -0
- package/dist/package.json +106 -0
- package/dist/src/Engine.d.ts +7 -0
- package/dist/src/Engine.js +47 -0
- package/dist/src/IConnectionOptions.d.ts +14 -0
- package/dist/src/IConnectionOptions.js +22 -0
- package/dist/src/IGenerationOptions.d.ts +24 -0
- package/dist/src/IGenerationOptions.js +33 -0
- package/dist/src/ModelCustomization.d.ts +4 -0
- package/dist/src/ModelCustomization.js +256 -0
- package/dist/src/ModelGeneration.d.ts +4 -0
- package/dist/src/ModelGeneration.js +247 -0
- package/dist/src/NamingStrategy.d.ts +10 -0
- package/dist/src/NamingStrategy.js +61 -0
- package/dist/src/Utils.d.ts +6 -0
- package/dist/src/Utils.js +68 -0
- package/dist/src/drivers/AbstractDriver.d.ts +30 -0
- package/dist/src/drivers/AbstractDriver.js +258 -0
- package/dist/src/drivers/MariaDbDriver.d.ts +4 -0
- package/dist/src/drivers/MariaDbDriver.js +11 -0
- package/dist/src/drivers/MssqlDriver.d.ts +25 -0
- package/dist/src/drivers/MssqlDriver.js +408 -0
- package/dist/src/drivers/MysqlDriver.d.ts +27 -0
- package/dist/src/drivers/MysqlDriver.js +439 -0
- package/dist/src/drivers/OracleDriver.d.ts +25 -0
- package/dist/src/drivers/OracleDriver.js +316 -0
- package/dist/src/drivers/PostgresDriver.d.ts +31 -0
- package/dist/src/drivers/PostgresDriver.js +542 -0
- package/dist/src/drivers/SqliteDriver.d.ts +28 -0
- package/dist/src/drivers/SqliteDriver.js +308 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +667 -0
- package/dist/src/library.d.ts +11 -0
- package/dist/src/library.js +14 -0
- package/dist/src/models/Column.d.ts +24 -0
- package/dist/src/models/Column.js +3 -0
- package/dist/src/models/Entity.d.ts +21 -0
- package/dist/src/models/Entity.js +3 -0
- package/dist/src/models/Index.d.ts +9 -0
- package/dist/src/models/Index.js +3 -0
- package/dist/src/models/Relation.d.ts +11 -0
- package/dist/src/models/Relation.js +3 -0
- package/dist/src/models/RelationId.d.ts +5 -0
- package/dist/src/models/RelationId.js +3 -0
- package/dist/src/models/RelationInternal.d.ts +11 -0
- package/dist/src/models/RelationInternal.js +3 -0
- package/dist/src/templates/entity.mst +47 -0
- package/dist/src/templates/index.mst +5 -0
- package/dist/src/templates/ormconfig.mst +17 -0
- package/dist/src/templates/tsconfig.mst +10 -0
- package/npminstall-debug.log +175 -0
- package/package.json +106 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const TypeormDriver = require("typeorm/driver/sqlserver/SqlServerDriver");
|
|
4
|
+
const TomgUtils = require("../Utils");
|
|
5
|
+
const AbstractDriver_1 = require("./AbstractDriver");
|
|
6
|
+
class MssqlDriver extends AbstractDriver_1.default {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.defaultValues = new TypeormDriver.SqlServerDriver({
|
|
10
|
+
options: { replication: undefined },
|
|
11
|
+
}).dataTypeDefaults;
|
|
12
|
+
this.standardPort = 1433;
|
|
13
|
+
this.standardSchema = "dbo";
|
|
14
|
+
this.standardUser = "sa";
|
|
15
|
+
try {
|
|
16
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, global-require, import/no-unresolved
|
|
17
|
+
this.MSSQL = require("mssql");
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
TomgUtils.LogError("", false, error);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async GetAllTables(schemas, dbNames) {
|
|
25
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
26
|
+
const response = (await request.query(`SELECT TABLE_SCHEMA,TABLE_NAME, table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES
|
|
27
|
+
WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${MssqlDriver.buildEscapedObjectList(schemas)}) AND TABLE_CATALOG in (${MssqlDriver.buildEscapedObjectList(dbNames)})`)).recordset;
|
|
28
|
+
// const response = await this.GetAllTablesQuery(schemas, dbNames);
|
|
29
|
+
const ret = [];
|
|
30
|
+
response.forEach((val) => {
|
|
31
|
+
ret.push({
|
|
32
|
+
columns: [],
|
|
33
|
+
indices: [],
|
|
34
|
+
relations: [],
|
|
35
|
+
relationIds: [],
|
|
36
|
+
sqlName: val.TABLE_NAME,
|
|
37
|
+
tscName: val.TABLE_NAME,
|
|
38
|
+
fileName: val.TABLE_NAME,
|
|
39
|
+
database: dbNames.length > 1 ? val.DB_NAME : "",
|
|
40
|
+
schema: val.TABLE_SCHEMA,
|
|
41
|
+
fileImports: [],
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return ret;
|
|
45
|
+
}
|
|
46
|
+
async GetCoulmnsFromEntity(entities, schemas, dbNames) {
|
|
47
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
48
|
+
const response = (await request.query(`SELECT c.TABLE_NAME,c.TABLE_SCHEMA,c.COLUMN_NAME,c.COLUMN_DEFAULT,IS_NULLABLE, DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
|
|
49
|
+
COLUMNPROPERTY(object_id(c.TABLE_SCHEMA + '.'+ c.TABLE_NAME),c. COLUMN_NAME, 'IsIdentity') IsIdentity,
|
|
50
|
+
CASE WHEN ISNULL(tc.cnt,0)>0 THEN 1 ELSE 0 END AS IsUnique
|
|
51
|
+
FROM INFORMATION_SCHEMA.COLUMNS c
|
|
52
|
+
LEFT JOIN (SELECT tc.TABLE_SCHEMA,tc.TABLE_NAME,cu.COLUMN_NAME,COUNT(1) AS cnt FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME where tc.CONSTRAINT_TYPE = 'UNIQUE' GROUP BY tc.TABLE_SCHEMA,tc.TABLE_NAME,cu.COLUMN_NAME) AS tc
|
|
53
|
+
on tc.TABLE_NAME = c.TABLE_NAME and tc.COLUMN_NAME = c.COLUMN_NAME and tc.TABLE_SCHEMA=c.TABLE_SCHEMA
|
|
54
|
+
where c.TABLE_SCHEMA in (${MssqlDriver.buildEscapedObjectList(schemas)}) AND c.TABLE_CATALOG in (${MssqlDriver.buildEscapedObjectList(dbNames)}) order by ordinal_position
|
|
55
|
+
`)).recordset;
|
|
56
|
+
entities.forEach((ent) => {
|
|
57
|
+
response
|
|
58
|
+
.filter((filterVal) => {
|
|
59
|
+
return (filterVal.TABLE_NAME === ent.tscName &&
|
|
60
|
+
filterVal.TABLE_SCHEMA === ent.schema);
|
|
61
|
+
})
|
|
62
|
+
.forEach((resp) => {
|
|
63
|
+
const tscName = resp.COLUMN_NAME;
|
|
64
|
+
const options = {
|
|
65
|
+
name: resp.COLUMN_NAME,
|
|
66
|
+
};
|
|
67
|
+
if (resp.IS_NULLABLE === "YES")
|
|
68
|
+
options.nullable = true;
|
|
69
|
+
if (resp.IsUnique === 1)
|
|
70
|
+
options.unique = true;
|
|
71
|
+
const generated = resp.IsIdentity === 1 ? true : undefined;
|
|
72
|
+
const defaultValue = MssqlDriver.ReturnDefaultValueFunction(resp.COLUMN_DEFAULT);
|
|
73
|
+
const columnType = resp.DATA_TYPE;
|
|
74
|
+
let tscType = "";
|
|
75
|
+
switch (resp.DATA_TYPE) {
|
|
76
|
+
case "bigint":
|
|
77
|
+
tscType = "string";
|
|
78
|
+
break;
|
|
79
|
+
case "bit":
|
|
80
|
+
tscType = "boolean";
|
|
81
|
+
break;
|
|
82
|
+
case "decimal":
|
|
83
|
+
tscType = "number";
|
|
84
|
+
break;
|
|
85
|
+
case "int":
|
|
86
|
+
tscType = "number";
|
|
87
|
+
break;
|
|
88
|
+
case "money":
|
|
89
|
+
tscType = "number";
|
|
90
|
+
break;
|
|
91
|
+
case "numeric":
|
|
92
|
+
tscType = "number";
|
|
93
|
+
break;
|
|
94
|
+
case "smallint":
|
|
95
|
+
tscType = "number";
|
|
96
|
+
break;
|
|
97
|
+
case "smallmoney":
|
|
98
|
+
tscType = "number";
|
|
99
|
+
break;
|
|
100
|
+
case "tinyint":
|
|
101
|
+
tscType = "number";
|
|
102
|
+
break;
|
|
103
|
+
case "float":
|
|
104
|
+
tscType = "number";
|
|
105
|
+
break;
|
|
106
|
+
case "real":
|
|
107
|
+
tscType = "number";
|
|
108
|
+
break;
|
|
109
|
+
case "date":
|
|
110
|
+
tscType = "Date";
|
|
111
|
+
break;
|
|
112
|
+
case "datetime2":
|
|
113
|
+
tscType = "Date";
|
|
114
|
+
break;
|
|
115
|
+
case "datetime":
|
|
116
|
+
tscType = "Date";
|
|
117
|
+
break;
|
|
118
|
+
case "datetimeoffset":
|
|
119
|
+
tscType = "Date";
|
|
120
|
+
break;
|
|
121
|
+
case "smalldatetime":
|
|
122
|
+
tscType = "Date";
|
|
123
|
+
break;
|
|
124
|
+
case "time":
|
|
125
|
+
tscType = "Date";
|
|
126
|
+
break;
|
|
127
|
+
case "char":
|
|
128
|
+
tscType = "string";
|
|
129
|
+
break;
|
|
130
|
+
case "text":
|
|
131
|
+
tscType = "string";
|
|
132
|
+
break;
|
|
133
|
+
case "varchar":
|
|
134
|
+
tscType = "string";
|
|
135
|
+
break;
|
|
136
|
+
case "nchar":
|
|
137
|
+
tscType = "string";
|
|
138
|
+
break;
|
|
139
|
+
case "ntext":
|
|
140
|
+
tscType = "string";
|
|
141
|
+
break;
|
|
142
|
+
case "nvarchar":
|
|
143
|
+
tscType = "string";
|
|
144
|
+
break;
|
|
145
|
+
case "binary":
|
|
146
|
+
tscType = "Buffer";
|
|
147
|
+
break;
|
|
148
|
+
case "image":
|
|
149
|
+
tscType = "Buffer";
|
|
150
|
+
break;
|
|
151
|
+
case "varbinary":
|
|
152
|
+
tscType = "Buffer";
|
|
153
|
+
break;
|
|
154
|
+
case "hierarchyid":
|
|
155
|
+
tscType = "string";
|
|
156
|
+
break;
|
|
157
|
+
case "sql_variant":
|
|
158
|
+
tscType = "string";
|
|
159
|
+
break;
|
|
160
|
+
case "timestamp":
|
|
161
|
+
tscType = "Date";
|
|
162
|
+
break;
|
|
163
|
+
case "uniqueidentifier":
|
|
164
|
+
tscType = "string";
|
|
165
|
+
break;
|
|
166
|
+
case "xml":
|
|
167
|
+
tscType = "string";
|
|
168
|
+
break;
|
|
169
|
+
case "geometry":
|
|
170
|
+
tscType = "string";
|
|
171
|
+
break;
|
|
172
|
+
case "geography":
|
|
173
|
+
tscType = "string";
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
tscType = "NonNullable<unknown>";
|
|
177
|
+
TomgUtils.LogError(`Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}`);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
if (this.ColumnTypesWithPrecision.some((v) => v === columnType)) {
|
|
181
|
+
if (resp.NUMERIC_PRECISION !== null) {
|
|
182
|
+
options.precision = resp.NUMERIC_PRECISION;
|
|
183
|
+
}
|
|
184
|
+
if (resp.NUMERIC_SCALE !== null) {
|
|
185
|
+
options.scale = resp.NUMERIC_SCALE;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (this.ColumnTypesWithLength.some((v) => v === columnType)) {
|
|
189
|
+
options.length =
|
|
190
|
+
resp.CHARACTER_MAXIMUM_LENGTH > 0
|
|
191
|
+
? resp.CHARACTER_MAXIMUM_LENGTH
|
|
192
|
+
: undefined;
|
|
193
|
+
}
|
|
194
|
+
ent.columns.push({
|
|
195
|
+
generated,
|
|
196
|
+
type: columnType,
|
|
197
|
+
default: defaultValue,
|
|
198
|
+
options,
|
|
199
|
+
tscName,
|
|
200
|
+
tscType,
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
return entities;
|
|
205
|
+
}
|
|
206
|
+
async GetIndexesFromEntity(entities, schemas, dbNames) {
|
|
207
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
208
|
+
/* eslint-disable camelcase */
|
|
209
|
+
const response = [];
|
|
210
|
+
/* eslint-enable camelcase */
|
|
211
|
+
/* eslint-disable no-await-in-loop */
|
|
212
|
+
for (const dbName of dbNames) {
|
|
213
|
+
if (dbNames.length > 1) {
|
|
214
|
+
await this.UseDB(dbName);
|
|
215
|
+
}
|
|
216
|
+
const resp = (await request.query(`SELECT
|
|
217
|
+
TableName = t.name,
|
|
218
|
+
TableSchema = s.name,
|
|
219
|
+
IndexName = ind.name,
|
|
220
|
+
ColumnName = col.name,
|
|
221
|
+
ind.is_unique,
|
|
222
|
+
ind.is_primary_key
|
|
223
|
+
FROM
|
|
224
|
+
sys.indexes ind
|
|
225
|
+
INNER JOIN
|
|
226
|
+
sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id
|
|
227
|
+
INNER JOIN
|
|
228
|
+
sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id
|
|
229
|
+
INNER JOIN
|
|
230
|
+
sys.tables t ON ind.object_id = t.object_id
|
|
231
|
+
INNER JOIN
|
|
232
|
+
sys.schemas s on s.schema_id=t.schema_id
|
|
233
|
+
WHERE
|
|
234
|
+
t.is_ms_shipped = 0 and s.name in (${MssqlDriver.buildEscapedObjectList(schemas)})
|
|
235
|
+
ORDER BY
|
|
236
|
+
t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset;
|
|
237
|
+
response.push(...resp);
|
|
238
|
+
}
|
|
239
|
+
/* eslint-enable no-await-in-loop */
|
|
240
|
+
entities.forEach((ent) => {
|
|
241
|
+
const entityIndices = response.filter((filterVal) => filterVal.TableName === ent.tscName &&
|
|
242
|
+
filterVal.TableSchema === ent.schema);
|
|
243
|
+
const indexNames = new Set(entityIndices.map((v) => v.IndexName));
|
|
244
|
+
indexNames.forEach((indexName) => {
|
|
245
|
+
const records = entityIndices.filter((v) => v.IndexName === indexName);
|
|
246
|
+
const indexInfo = {
|
|
247
|
+
columns: [],
|
|
248
|
+
options: {},
|
|
249
|
+
name: records[0].IndexName,
|
|
250
|
+
};
|
|
251
|
+
if (records[0].is_primary_key)
|
|
252
|
+
indexInfo.primary = true;
|
|
253
|
+
if (records[0].is_unique)
|
|
254
|
+
indexInfo.options.unique = true;
|
|
255
|
+
records.forEach((record) => {
|
|
256
|
+
indexInfo.columns.push(record.ColumnName);
|
|
257
|
+
});
|
|
258
|
+
ent.indices.push(indexInfo);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
return entities;
|
|
262
|
+
}
|
|
263
|
+
async GetRelations(entities, schemas, dbNames, generationOptions) {
|
|
264
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
265
|
+
const response = [];
|
|
266
|
+
/* eslint-disable no-await-in-loop */
|
|
267
|
+
for (const dbName of dbNames) {
|
|
268
|
+
if (dbNames.length > 1) {
|
|
269
|
+
await this.UseDB(dbName);
|
|
270
|
+
}
|
|
271
|
+
const resp = (await request.query(`select
|
|
272
|
+
parentTable.name as TableWithForeignKey,
|
|
273
|
+
fkc.constraint_column_id as FK_PartNo,
|
|
274
|
+
parentColumn.name as ForeignKeyColumn,
|
|
275
|
+
referencedTable.name as TableReferenced,
|
|
276
|
+
referencedColumn.name as ForeignKeyColumnReferenced,
|
|
277
|
+
fk.delete_referential_action_desc as onDelete,
|
|
278
|
+
fk.update_referential_action_desc as onUpdate,
|
|
279
|
+
fk.object_id as objectId
|
|
280
|
+
from
|
|
281
|
+
sys.foreign_keys fk
|
|
282
|
+
inner join
|
|
283
|
+
sys.foreign_key_columns as fkc on fkc.constraint_object_id=fk.object_id
|
|
284
|
+
inner join
|
|
285
|
+
sys.tables as parentTable on fkc.parent_object_id = parentTable.object_id
|
|
286
|
+
inner join
|
|
287
|
+
sys.columns as parentColumn on fkc.parent_object_id = parentColumn.object_id and fkc.parent_column_id = parentColumn.column_id
|
|
288
|
+
inner join
|
|
289
|
+
sys.tables as referencedTable on fkc.referenced_object_id = referencedTable.object_id
|
|
290
|
+
inner join
|
|
291
|
+
sys.columns as referencedColumn on fkc.referenced_object_id = referencedColumn.object_id and fkc.referenced_column_id = referencedColumn.column_id
|
|
292
|
+
inner join
|
|
293
|
+
sys.schemas as parentSchema on parentSchema.schema_id=parentTable.schema_id
|
|
294
|
+
where
|
|
295
|
+
fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name in (${MssqlDriver.buildEscapedObjectList(schemas)})
|
|
296
|
+
order by
|
|
297
|
+
TableWithForeignKey, FK_PartNo`)).recordset;
|
|
298
|
+
response.push(...resp);
|
|
299
|
+
}
|
|
300
|
+
/* eslint-enable no-await-in-loop */
|
|
301
|
+
const relationsTemp = [];
|
|
302
|
+
const relationKeys = new Set(response.map((v) => v.objectId));
|
|
303
|
+
relationKeys.forEach((relationId) => {
|
|
304
|
+
const rows = response.filter((v) => v.objectId === relationId);
|
|
305
|
+
const ownerTable = entities.find((v) => v.sqlName === rows[0].TableWithForeignKey);
|
|
306
|
+
const relatedTable = entities.find((v) => v.sqlName === rows[0].TableReferenced);
|
|
307
|
+
if (!ownerTable || !relatedTable) {
|
|
308
|
+
TomgUtils.LogError(`Relation between tables ${rows[0].TableWithForeignKey} and ${rows[0].TableReferenced} wasn't found in entity model.`, true);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const internal = {
|
|
312
|
+
ownerColumns: [],
|
|
313
|
+
relatedColumns: [],
|
|
314
|
+
ownerTable,
|
|
315
|
+
relatedTable,
|
|
316
|
+
};
|
|
317
|
+
switch (rows[0].onDelete) {
|
|
318
|
+
case "NO_ACTION":
|
|
319
|
+
break;
|
|
320
|
+
case "SET_NULL":
|
|
321
|
+
internal.onDelete = "SET NULL";
|
|
322
|
+
break;
|
|
323
|
+
default:
|
|
324
|
+
internal.onDelete = rows[0].onDelete;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
switch (rows[0].onUpdate) {
|
|
328
|
+
case "NO_ACTION":
|
|
329
|
+
break;
|
|
330
|
+
case "SET_NULL":
|
|
331
|
+
internal.onUpdate = "SET NULL";
|
|
332
|
+
break;
|
|
333
|
+
default:
|
|
334
|
+
internal.onUpdate = rows[0].onUpdate;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
rows.forEach((row) => {
|
|
338
|
+
internal.ownerColumns.push(row.ForeignKeyColumn);
|
|
339
|
+
internal.relatedColumns.push(row.ForeignKeyColumnReferenced);
|
|
340
|
+
});
|
|
341
|
+
relationsTemp.push(internal);
|
|
342
|
+
});
|
|
343
|
+
const retVal = MssqlDriver.GetRelationsFromRelationTempInfo(relationsTemp, entities, generationOptions);
|
|
344
|
+
return retVal;
|
|
345
|
+
}
|
|
346
|
+
async DisconnectFromServer() {
|
|
347
|
+
if (this.Connection) {
|
|
348
|
+
await this.Connection.close();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async ConnectToServer(connectionOptons) {
|
|
352
|
+
const databaseName = connectionOptons.databaseNames[0];
|
|
353
|
+
const config = {
|
|
354
|
+
database: databaseName,
|
|
355
|
+
options: {
|
|
356
|
+
appName: "typeorm-model-generator",
|
|
357
|
+
encrypt: connectionOptons.ssl,
|
|
358
|
+
instanceName: connectionOptons.instanceName,
|
|
359
|
+
},
|
|
360
|
+
password: connectionOptons.password,
|
|
361
|
+
port: connectionOptons.port,
|
|
362
|
+
requestTimeout: 60 * 60 * 1000,
|
|
363
|
+
server: connectionOptons.host,
|
|
364
|
+
user: connectionOptons.user,
|
|
365
|
+
};
|
|
366
|
+
const promise = new Promise((resolve, reject) => {
|
|
367
|
+
this.Connection = new this.MSSQL.ConnectionPool(config, (err) => {
|
|
368
|
+
if (!err) {
|
|
369
|
+
resolve(true);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
TomgUtils.LogError("Error connecting to MSSQL Server.", false, err.message);
|
|
373
|
+
reject(err);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
await promise;
|
|
378
|
+
}
|
|
379
|
+
async CreateDB(dbName) {
|
|
380
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
381
|
+
await request.query(`CREATE DATABASE "${dbName}"; `);
|
|
382
|
+
}
|
|
383
|
+
async UseDB(dbName) {
|
|
384
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
385
|
+
await request.query(`USE "${dbName}"; `);
|
|
386
|
+
}
|
|
387
|
+
async DropDB(dbName) {
|
|
388
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
389
|
+
await request.query(`DROP DATABASE "${dbName}"; `);
|
|
390
|
+
}
|
|
391
|
+
async CheckIfDBExists(dbName) {
|
|
392
|
+
const request = new this.MSSQL.Request(this.Connection);
|
|
393
|
+
const resp = await request.query(`SELECT name FROM master.sys.databases WHERE name = N'${dbName}' `);
|
|
394
|
+
return resp.recordset.length > 0;
|
|
395
|
+
}
|
|
396
|
+
static ReturnDefaultValueFunction(defVal) {
|
|
397
|
+
let defaultValue = defVal;
|
|
398
|
+
if (!defaultValue) {
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
if (defaultValue.startsWith("(") && defaultValue.endsWith(")")) {
|
|
402
|
+
defaultValue = defaultValue.slice(1, -1);
|
|
403
|
+
}
|
|
404
|
+
return `() => "${defaultValue}"`;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
exports.default = MssqlDriver;
|
|
408
|
+
//# sourceMappingURL=MssqlDriver.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DataTypeDefaults } from "typeorm/driver/types/DataTypeDefaults";
|
|
2
|
+
import AbstractDriver from "./AbstractDriver";
|
|
3
|
+
import IConnectionOptions from "../IConnectionOptions";
|
|
4
|
+
import { Entity } from "../models/Entity";
|
|
5
|
+
import IGenerationOptions from "../IGenerationOptions";
|
|
6
|
+
export default class MysqlDriver extends AbstractDriver {
|
|
7
|
+
defaultValues: DataTypeDefaults;
|
|
8
|
+
readonly EngineName: string;
|
|
9
|
+
readonly standardPort = 3306;
|
|
10
|
+
readonly standardUser = "root";
|
|
11
|
+
readonly standardSchema = "";
|
|
12
|
+
private MYSQL;
|
|
13
|
+
private Connection;
|
|
14
|
+
constructor();
|
|
15
|
+
GetAllTables(schemas: string[], dbNames: string[]): Promise<Entity[]>;
|
|
16
|
+
GetCoulmnsFromEntity(entities: Entity[], schemas: string[], dbNames: string[]): Promise<Entity[]>;
|
|
17
|
+
GetIndexesFromEntity(entities: Entity[], schemas: string[], dbNames: string[]): Promise<Entity[]>;
|
|
18
|
+
GetRelations(entities: Entity[], schemas: string[], dbNames: string[], generationOptions: IGenerationOptions): Promise<Entity[]>;
|
|
19
|
+
DisconnectFromServer(): Promise<void>;
|
|
20
|
+
ConnectToServer(connectionOptons: IConnectionOptions): Promise<void>;
|
|
21
|
+
CreateDB(dbName: string): Promise<void>;
|
|
22
|
+
UseDB(dbName: string): Promise<void>;
|
|
23
|
+
DropDB(dbName: string): Promise<void>;
|
|
24
|
+
CheckIfDBExists(dbName: string): Promise<boolean>;
|
|
25
|
+
ExecQuery<T>(sql: string): Promise<T[]>;
|
|
26
|
+
private static ReturnDefaultValueFunction;
|
|
27
|
+
}
|