@@ -180,8 +180,9 @@ export class SqlSimpleParser {
180180 }
181181
182182 //Verify if this is a property that doesn't have a relationship (One minute of silence for the property)
183+ // TODO: make primary key check a regex match/ contains w/ () space or not
183184 var normalProperty =
184- propertyType . indexOf ( Primary_Key ) == - 1 &&
185+ ! propertyType . match ( / P R I M A R Y K E Y \s ? \( / gi ) &&
185186 propertyType . indexOf ( Foreign_Key ) == - 1 &&
186187 propertyType . indexOf ( CONSTRAINT_Primary_Key ) == - 1 &&
187188 propertyType . indexOf ( CONSTRAINT_Foreign_Key ) == - 1 ;
@@ -255,33 +256,26 @@ export class SqlSimpleParser {
255256
256257 //Add Property to table
257258 currentTableModel . Properties . push ( propertyModel ) ;
258- }
259-
260- //Parse Primary Key
261- if (
262- propertyType . indexOf ( Primary_Key ) != - 1 ||
263- propertyType . indexOf ( CONSTRAINT_Primary_Key ) != - 1
264- ) {
265- if ( ! this . MODE_SQLSERVER ) {
266- var primaryKey = name
267- . replace ( / P R I M A R Y K E Y \s ? \( / gi, "" )
268- . replace ( ")" , "" ) ;
269259
260+ if (
261+ ExtendedProperties . toLocaleLowerCase ( ) . indexOf ( Primary_Key ) > - 1
262+ ) {
270263 //Create Primary Key
271264 var primaryKeyModel = this . CreatePrimaryKey (
272- primaryKey ,
265+ name ,
273266 currentTableModel . Name
274267 ) ;
275268
276269 //Add Primary Key to List
277270 this . primaryKeyList . push ( primaryKeyModel ) ;
278- } else {
279- // var start = i + 2;
280- // var end = 0;
281- if (
282- propertyRow . indexOf ( Primary_Key ) !== - 1 &&
283- nameSkipCheck . indexOf ( "CLUSTERED" ) === - 1
284- ) {
271+ }
272+ } else {
273+ //Parse Primary Key
274+ if (
275+ propertyType . indexOf ( Primary_Key ) != - 1 ||
276+ propertyType . indexOf ( CONSTRAINT_Primary_Key ) != - 1
277+ ) {
278+ if ( ! this . MODE_SQLSERVER ) {
285279 var primaryKey = name
286280 . replace ( / P R I M A R Y K E Y \s ? \( / gi, "" )
287281 . replace ( ")" , "" ) ;
@@ -295,38 +289,56 @@ export class SqlSimpleParser {
295289 //Add Primary Key to List
296290 this . primaryKeyList . push ( primaryKeyModel ) ;
297291 } else {
298- var startIndex =
299- name . toLocaleLowerCase ( ) . indexOf ( "(" ) ;
300- var endIndex = name . indexOf ( ")" ) + 1 ;
301- var primaryKey = name
302- . substring ( startIndex , endIndex )
303- . replace ( "(" , "" )
304- . replace ( ")" , "" )
305- . replace ( / A S C / gi, "" )
306- . trim ( ) ;
307-
308- const columnQuantifiers = this . GetColumnQuantifiers ( ) ;
309- //Get delimiter of column name
310- var firstSpaceIndex =
311- primaryKey [ 0 ] == columnQuantifiers . Start &&
312- primaryKey . indexOf ( columnQuantifiers . End + " " ) !== - 1
313- ? primaryKey . indexOf ( columnQuantifiers . End + " " )
314- : primaryKey . indexOf ( " " ) ;
315-
316- var primaryKeyRow =
317- firstSpaceIndex == - 1
318- ? primaryKey
319- : primaryKey . substring ( firstSpaceIndex + 1 ) . trim ( ) ;
292+ // var start = i + 2;
293+ // var end = 0;
294+ if (
295+ propertyRow . indexOf ( Primary_Key ) !== - 1 &&
296+ nameSkipCheck . indexOf ( "CLUSTERED" ) === - 1
297+ ) {
298+ var primaryKey = name
299+ . replace ( / P R I M A R Y K E Y \s ? \( / gi, "" )
300+ . replace ( ")" , "" ) ;
320301
321- //Create Primary Key
322- var primaryKeyModel = this . CreatePrimaryKey (
323- primaryKeyRow ,
324- currentTableModel . Name
325- ) ;
302+ //Create Primary Key
303+ var primaryKeyModel = this . CreatePrimaryKey (
304+ primaryKey ,
305+ currentTableModel . Name
306+ ) ;
326307
327- //Add Primary Key to List
328- this . primaryKeyList . push ( primaryKeyModel ) ;
329- /*
308+ //Add Primary Key to List
309+ this . primaryKeyList . push ( primaryKeyModel ) ;
310+ } else {
311+ var startIndex = name . toLocaleLowerCase ( ) . indexOf ( "(" ) ;
312+ var endIndex = name . indexOf ( ")" ) + 1 ;
313+ var primaryKey = name
314+ . substring ( startIndex , endIndex )
315+ . replace ( "(" , "" )
316+ . replace ( ")" , "" )
317+ . replace ( / A S C / gi, "" )
318+ . trim ( ) ;
319+
320+ const columnQuantifiers = this . GetColumnQuantifiers ( ) ;
321+ //Get delimiter of column name
322+ var firstSpaceIndex =
323+ primaryKey [ 0 ] == columnQuantifiers . Start &&
324+ primaryKey . indexOf ( columnQuantifiers . End + " " ) !== - 1
325+ ? primaryKey . indexOf ( columnQuantifiers . End + " " )
326+ : primaryKey . indexOf ( " " ) ;
327+
328+ var primaryKeyRow =
329+ firstSpaceIndex == - 1
330+ ? primaryKey
331+ : primaryKey . substring ( firstSpaceIndex + 1 ) . trim ( ) ;
332+
333+ //Create Primary Key
334+ var primaryKeyModel = this . CreatePrimaryKey (
335+ primaryKeyRow ,
336+ currentTableModel . Name
337+ ) ;
338+
339+ //Add Primary Key to List
340+ this . primaryKeyList . push ( primaryKeyModel ) ;
341+ /*
330342 while (end === 0) {
331343 var primaryKeyRow = lines[start].trim();
332344
@@ -352,6 +364,7 @@ export class SqlSimpleParser {
352364 this.primaryKeyList.push(primaryKeyModel);
353365 }
354366 */
367+ }
355368 }
356369 }
357370 }
0 commit comments