@@ -896,11 +896,11 @@ const generate_sql_ddl_1 = require("@funktechno/little-mermaid-2-the-sql/lib/src
896
896
const sqlsimpleparser_1 = require ( "@funktechno/sqlsimpleparser" ) ;
897
897
/**
898
898
* SQL Tools Plugin for importing diagrams from SQL DDL and exporting to SQL.
899
- * Version: 0.0.2
899
+ * Version: 0.0.3
900
900
*/
901
901
Draw . loadPlugin ( function ( ui ) {
902
902
// export sql methods
903
- const pluginVersion = "0.0.2 " ;
903
+ const pluginVersion = "0.0.3 " ;
904
904
//Create Base div
905
905
const divGenSQL = document . createElement ( "div" ) ;
906
906
divGenSQL . style . userSelect = "none" ;
@@ -1043,14 +1043,14 @@ Draw.loadPlugin(function (ui) {
1043
1043
// has to be one to many and not one to one
1044
1044
if ( ( targetIsPrimary || sourceIsPrimary ) &&
1045
1045
! ( targetIsPrimary && sourceIsPrimary ) ) {
1046
- var sourceId = edge . source . value ;
1047
- var sourceAttr = getDbLabel ( sourceId , columnQuantifiers ) ;
1046
+ let sourceId = edge . source . value ;
1047
+ const sourceAttr = getDbLabel ( sourceId , columnQuantifiers ) ;
1048
1048
sourceId = sourceAttr . attributeName ;
1049
- var sourceEntity = RemoveNameQuantifiers ( edge . source . parent . value ) ;
1050
- var targetId = edge . target . value ;
1051
- var targetAttr = getDbLabel ( targetId , columnQuantifiers ) ;
1049
+ const sourceEntity = RemoveNameQuantifiers ( edge . source . parent . value ) ;
1050
+ let targetId = edge . target . value ;
1051
+ const targetAttr = getDbLabel ( targetId , columnQuantifiers ) ;
1052
1052
targetId = targetAttr . attributeName ;
1053
- var targetEntity = RemoveNameQuantifiers ( edge . target . parent . value ) ;
1053
+ const targetEntity = RemoveNameQuantifiers ( edge . target . parent . value ) ;
1054
1054
// entityA primary
1055
1055
// entityB foreign
1056
1056
const relationship = {
@@ -1067,23 +1067,23 @@ Draw.loadPlugin(function (ui) {
1067
1067
`[${ targetEntity } .${ targetId } ] to [${ sourceEntity } .${ sourceId } ]`
1068
1068
} ;
1069
1069
// check that is doesn't already exist
1070
- var exists = relationships . findIndex ( r => r . entityA == relationship . entityA && r . entityB == relationship . entityB && r . roleA == relationship . roleA ) ;
1070
+ const exists = relationships . findIndex ( r => r . entityA == relationship . entityA && r . entityB == relationship . entityB && r . roleA == relationship . roleA ) ;
1071
1071
if ( exists == - 1 ) {
1072
1072
relationships . push ( relationship ) ;
1073
1073
}
1074
1074
}
1075
1075
else if ( targetIsPrimary && sourceIsPrimary ) {
1076
1076
// add a new many to many table
1077
- var sourceId = edge . source . value ;
1078
- sourceAttr = getDbLabel ( sourceId , columnQuantifiers ) ;
1077
+ let sourceId = edge . source . value ;
1078
+ const sourceAttr = getDbLabel ( sourceId , columnQuantifiers ) ;
1079
1079
sourceAttr . attributeKeyType = "PK" ;
1080
1080
sourceId = sourceAttr . attributeName ;
1081
- var sourceEntity = RemoveNameQuantifiers ( edge . source . parent . value ) ;
1082
- var targetId = edge . target . value ;
1083
- targetAttr = getDbLabel ( targetId , columnQuantifiers ) ;
1081
+ const sourceEntity = RemoveNameQuantifiers ( edge . source . parent . value ) ;
1082
+ let targetId = edge . target . value ;
1083
+ const targetAttr = getDbLabel ( targetId , columnQuantifiers ) ;
1084
1084
targetAttr . attributeKeyType = "PK" ;
1085
1085
targetId = targetAttr . attributeName ;
1086
- var targetEntity = RemoveNameQuantifiers ( edge . target . parent . value ) ;
1086
+ const targetEntity = RemoveNameQuantifiers ( edge . target . parent . value ) ;
1087
1087
const compositeEntity = {
1088
1088
name : RemoveNameQuantifiers ( sourceEntity ) + "_" + RemoveNameQuantifiers ( targetEntity ) ,
1089
1089
attributes : [ sourceAttr , targetAttr ]
@@ -1109,7 +1109,7 @@ Draw.loadPlugin(function (ui) {
1109
1109
roleA : `[${ sourceEntity } .${ sourceId } ] to [${ compositeEntity . name } .${ sourceId } ]`
1110
1110
} ;
1111
1111
// check that is doesn't already exist
1112
- var exists = relationships . findIndex ( r => r . entityA == relationship . entityA && r . entityB == relationship . entityB && r . roleA == relationship . roleA ) ;
1112
+ let exists = relationships . findIndex ( r => r . entityA == relationship . entityA && r . entityB == relationship . entityB && r . roleA == relationship . roleA ) ;
1113
1113
if ( exists == - 1 ) {
1114
1114
relationships . push ( relationship ) ;
1115
1115
}
@@ -1179,7 +1179,7 @@ Draw.loadPlugin(function (ui) {
1179
1179
// update sql value in text area
1180
1180
sqlInputGenSQL . value = sql ;
1181
1181
// TODO: use selection as well?
1182
- const modelSelected = ui . editor . graph . getSelectionModel ( ) ;
1182
+ // const modelSelected = ui.editor.graph.getSelectionModel();
1183
1183
}
1184
1184
;
1185
1185
mxUtils . br ( divGenSQL ) ;
@@ -1238,18 +1238,16 @@ Draw.loadPlugin(function (ui) {
1238
1238
divFromSQL . style . overflow = "hidden" ;
1239
1239
divFromSQL . style . padding = "10px" ;
1240
1240
divFromSQL . style . height = "100%" ;
1241
- var graph = ui . editor . graph ;
1242
1241
const sqlInputFromSQL = document . createElement ( "textarea" ) ;
1243
1242
sqlInputFromSQL . style . height = "200px" ;
1244
1243
sqlInputFromSQL . style . width = "100%" ;
1245
- const defaultReset = `/*\n\tDrawio default value\n\tPlugin: sql\n\tVersion: ${ pluginVersion } \n*/\n\nCREATE TABLE Persons\n(\n PersonID int NOT NULL,\n LastName varchar (255),\n " +
1246
- "FirstName varchar (255),\n Address varchar (255),\n City varchar (255),\n Primary Key(PersonID)\n);\n\n" +
1244
+ const defaultReset = `/*\n\tDrawio default value\n\tPlugin: sql\n\tVersion: ${ pluginVersion } \n*/\n\nCREATE TABLE Persons\n(\n PersonID int NOT NULL,\n LastName constchar (255),\n " +
1245
+ "FirstName constchar (255),\n Address constchar (255),\n City constchar (255),\n Primary Key(PersonID)\n);\n\n" +
1247
1246
"CREATE TABLE Orders\n(\n OrderID int NOT NULL PRIMARY KEY,\n PersonID int NOT NULL,\n FOREIGN KEY ([PersonID]) REFERENCES [Persons]([PersonID])" +
1248
1247
"\n);` ;
1249
1248
sqlInputFromSQL . value = defaultReset ;
1250
1249
mxUtils . br ( divFromSQL ) ;
1251
1250
divFromSQL . appendChild ( sqlInputFromSQL ) ;
1252
- var graph = ui . editor . graph ;
1253
1251
// Extends Extras menu
1254
1252
mxResources . parse ( "fromSql=From SQL" ) ;
1255
1253
const wndFromSQL = new mxWindow ( mxResources . get ( "fromSql" ) , divFromSQL , document . body . offsetWidth - 480 , 140 , 320 , 320 , true , true ) ;
@@ -1335,7 +1333,7 @@ Draw.loadPlugin(function (ui) {
1335
1333
// add foreign key edges
1336
1334
const model = graph . getModel ( ) ;
1337
1335
const columnQuantifiers = GetColumnQuantifiers ( type ) ;
1338
- const pt = graph . getFreeInsertPoint ( ) ;
1336
+ // const pt = graph.getFreeInsertPoint();
1339
1337
foreignKeyList . forEach ( function ( fk ) {
1340
1338
if ( fk . IsDestination && fk . PrimaryKeyName && fk . ReferencesPropertyName &&
1341
1339
fk . PrimaryKeyTableName && fk . ReferencesTableName ) {
@@ -1446,7 +1444,7 @@ Draw.loadPlugin(function (ui) {
1446
1444
} ;
1447
1445
}
1448
1446
if ( theMenuExportAs && ! window . VsCodeApi ) {
1449
- var oldMenuExportAs = theMenuExportAs . funct ;
1447
+ const oldMenuExportAs = theMenuExportAs . funct ;
1450
1448
theMenuExportAs . funct = function ( ...args ) {
1451
1449
const [ menu , parent ] = args ;
1452
1450
oldMenuExportAs . apply ( this , args ) ;
@@ -1457,7 +1455,7 @@ Draw.loadPlugin(function (ui) {
1457
1455
// vscode file export sql menu
1458
1456
const menu = ui . menus . get ( "file" ) ;
1459
1457
if ( menu && menu . enabled ) {
1460
- var oldMenuExportAs = menu . funct ;
1458
+ const oldMenuExportAs = menu . funct ;
1461
1459
menu . funct = function ( ...args ) {
1462
1460
const [ menu , parent ] = args ;
1463
1461
oldMenuExportAs . apply ( this , args ) ;
0 commit comments