X-Git-Url: https://git.auder.net/?p=erdiag.git;a=blobdiff_plain;f=parser.js;fp=parser.js;h=2b75709dddeae00dddf82d8787b9d686a7d70033;hp=6d43d4f68ee77be1a778fa0fed71fb4259a730f3;hb=8edb29ffa12fda61a939295ce00a6d22133131d1;hpb=7a80e6db5860033f0a922d54cc0ba3e950f4f268 diff --git a/parser.js b/parser.js index 6d43d4f..2b75709 100644 --- a/parser.js +++ b/parser.js @@ -100,13 +100,12 @@ class ErDiags field.isKey = true; line = line.slice(1); } - field.name = line.match(/[^()"\s]+/)[0]; - let parenthesis = line.match(/\((.+)\)/); - if (parenthesis !== null) + field.name = line.match(/[^"\s]+/)[0]; + let sqlClues = line.substring(field.name.length).trim(); + if (sqlClues.length > 0) { - let sqlClues = parenthesis[1]; field.type = sqlClues.match(/[^\s]+/)[0]; //type is always the first indication (mandatory) - field.qualifiers = sqlClues.substring(field.type.length).trim(); + field.qualifiers = sqlClues.substring(field.type.length); } attributes.push(field); } @@ -167,12 +166,15 @@ class ErDiags Object.keys(this.entities).forEach( name => { let newTable = [ ]; //array of fields this.entities[name].attributes.forEach( attr => { - newTable.push({ + let newField = { name: attr.name, type: attr.type, isKey: attr.isKey, qualifiers: attr.qualifiers, - }); + }; + if (!!attr.qualifiers && !!attr.qualifiers.match(/foreign/i)) + Object.assign(newField, {ref: attr.qualifiers.match(/references ([^\s]+)/i)[1]}); + newTable.push(newField); }); this.tables[name] = newTable; }); @@ -439,7 +441,7 @@ class ErDiags mldDot += '"' + name + '" [label=<
' + name + ' |
' + label + ' |