this.tables = { };
this.mcdParsing(description);
this.mldParsing();
+
+ console.log(this.tables);
+
// Cache SVG graphs returned by server (in addition to server cache = good perfs)
this.mcdGraph = "";
this.mldGraph = "";
isKey: e.card.length >= 2 && e.card[1] == 'R', //"weak tables" foreign keys become part of the key
name: "#" + e2.name + "_" + attr.name,
type: attr.type,
- qualifiers: "foreign key references " + e2.name + " " + (e.card[0]=='1' : "not null" : ""),
+ qualifiers: "foreign key references " + e2.name + " " + (e.card[0]=='1' ? "not null" : ""),
ref: e2.name, //easier drawMld function (fewer regexps)
});
}
else
{
// Add all keys in current entity
- let fields = e.attributes.filter( attr => { return attr.isKey; });
+ let fields = this.entities[e.name].attributes.filter( attr => { return attr.isKey; });
newTableAttrs.push({
fields: fields,
entity: e.name,
});
}
- }
+ });
if (newTableAttrs.length > 1)
{
// Ok, really create a new table
let newTable = {
- name: a.name || newTableAttrs.map( item => { return item.entity; }).join("_");
+ name: a.name || newTableAttrs.map( item => { return item.entity; }).join("_"),
fields: [ ],
};
newTableAttrs.forEach( item => {
newTable.fields.push({
name: item.entity + "_" + f.name,
isKey: true,
- type: f.type,,
+ type: f.type,
qualifiers: (f.qualifiers+" " || "") + "foreign key references " + item.entity + " not null",
ref: item.entity,
});
_.shuffle(Object.keys(this.tables)).forEach( name => {
mldDot += '"' + name + '" [label=<<table BORDER="1" ALIGN="LEFT" CELLPADDING="5" CELLSPACING="0">\n';
mldDot += '<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">' + name + '</font></td></tr>\n';
- this.tables[name].fields.forEach( f => {
+ this.tables[name].forEach( f => {
let label = (f.isKey ? '<u>' : '') + (!!f.qualifiers && f.qualifiers.indexOf("foreign")>=0 ? '#' : '') + f.name + (f.isKey ? '</u>' : '');
mldDot += '<tr><td port="' + f.name + '"' + (f.isKey ? ' port="__key"' : '')
+ ' BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >' + label + '</font></td></tr>\n';
if (!!f.ref)
{
if (Math.random() < 0.5)
- links += '"' + f.ref + '":__key -- "' + '"'+name+'":"'+f.name+'"\n';
+ links += '"' + f.ref + '":__key -- "' + name+'":"'+f.name+'"\n';
else
links += '"'+name+'":"'+f.name+'" -- "' + f.ref + '":__key\n';
}
});
mldDot += links + '\n';
mldDot += '}\n';
- //console.log(mldDot);
+ console.log(mldDot);
ErDiags.AjaxGet(mldDot, graphSvg => {
this.mldGraph = graphSvg;
element.innerHTML = graphSvg;
--- /dev/null
+graph {
+node [shape=plaintext];
+"Instrument" [label=<<table BORDER="1" ALIGN="LEFT" CELLPADDING="5" CELLSPACING="0">
+<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">Instrument</font></td></tr>
+<tr><td port="name" port="__key" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" ><u>name</u></font></td></tr>
+<tr><td port="family" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >family</font></td></tr>
+</table>>];
+"Piano" [label=<<table BORDER="1" ALIGN="LEFT" CELLPADDING="5" CELLSPACING="0">
+<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">Piano</font></td></tr>
+<tr><td port="type" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >type</font></td></tr>
+</table>>];
+"Guitar" [label=<<table BORDER="1" ALIGN="LEFT" CELLPADDING="5" CELLSPACING="0">
+<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">Guitar</font></td></tr>
+<tr><td port="type" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >type</font></td></tr>
+</table>>];
+"Play" [label=<<table BORDER="1" ALIGN="LEFT" CELLPADDING="5" CELLSPACING="0">
+<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">Play</font></td></tr>
+<tr><td port="Musician_id" port="__key" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" ><u>#Musician_id</u></font></td></tr>
+<tr><td port="Instrument_name" port="__key" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" ><u>#Instrument_name</u></font></td></tr>
+<tr><td port="event" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >event</font></td></tr>
+</table>>];
+"Musician" [label=<<table BORDER="1" ALIGN="LEFT" CELLPADDING="5" CELLSPACING="0">
+<tr><td BGCOLOR="#ae7d4e" BORDER="0"><font COLOR="#FFFFFF">Musician</font></td></tr>
+<tr><td port="id" port="__key" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" ><u>id</u></font></td></tr>
+<tr><td port="name" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >name</font></td></tr>
+<tr><td port="band" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >band</font></td></tr>
+<tr><td port="role" BGCOLOR="#FFFFFF" BORDER="0" ALIGN="LEFT"><font COLOR="#000000" >role</font></td></tr>
+</table>>];
+"Play":"Musician_id" -- "Musician":__key
+"Instrument":__key -- ""Play":"Instrument_name"
+
+}