Skip to content

Commit 2c2521d

Browse files
committed
improved composite key pk lookup
1 parent 51f17bf commit 2c2521d

File tree

2 files changed

+448
-179
lines changed

2 files changed

+448
-179
lines changed

src/index.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class SqlSimpleParser {
273273
);
274274

275275
//Add Primary Key to List
276-
this.primaryKeyList.push(primaryKeyModel);
276+
this.primaryKeyList = this.primaryKeyList.concat(primaryKeyModel);
277277
}
278278
} else {
279279
//Parse Primary Key
@@ -293,7 +293,7 @@ export class SqlSimpleParser {
293293
);
294294

295295
//Add Primary Key to List
296-
this.primaryKeyList.push(primaryKeyModel);
296+
this.primaryKeyList = this.primaryKeyList.concat(primaryKeyModel);
297297
} else {
298298
// let start = i + 2;
299299
// let end = 0;
@@ -312,7 +312,7 @@ export class SqlSimpleParser {
312312
);
313313

314314
//Add Primary Key to List
315-
this.primaryKeyList.push(primaryKeyModel);
315+
this.primaryKeyList = this.primaryKeyList.concat(primaryKeyModel);
316316
} else {
317317
const startIndex = name.toLocaleLowerCase().indexOf("(");
318318
const endIndex = name.indexOf(")") + 1;
@@ -343,7 +343,7 @@ export class SqlSimpleParser {
343343
);
344344

345345
//Add Primary Key to List
346-
this.primaryKeyList.push(primaryKeyModel);
346+
this.primaryKeyList = this.primaryKeyList.concat(primaryKeyModel);
347347
/*
348348
while (end === 0) {
349349
let primaryKeyRow = lines[start].trim();
@@ -503,13 +503,22 @@ export class SqlSimpleParser {
503503
private CreatePrimaryKey(
504504
primaryKeyName: string,
505505
primaryKeyTableName: string
506-
) {
507-
const primaryKey: PrimaryKeyModel = {
508-
PrimaryKeyTableName: primaryKeyTableName,
509-
PrimaryKeyName: this.RemoveNameQuantifiers(primaryKeyName),
510-
};
506+
):PrimaryKeyModel[] {
507+
const primaryKeyNames = this.RemoveNameQuantifiers(primaryKeyName)
508+
.split(",")
509+
.filter((n) => n)
510+
// remove multiple spaces
511+
.map((n) => n.replace(/\s+/g, " ").trim());
512+
const primaryKeys:PrimaryKeyModel[] = [];
513+
primaryKeyNames.forEach(name => {
514+
const primaryKey: PrimaryKeyModel = {
515+
PrimaryKeyTableName: primaryKeyTableName,
516+
PrimaryKeyName: name,
517+
};
518+
primaryKeys.push(primaryKey);
519+
});
511520

512-
return primaryKey;
521+
return primaryKeys;
513522
}
514523

515524
private CreateProperty(

0 commit comments

Comments
 (0)