@@ -898,7 +898,7 @@ const sharedUtils_1 = require("./utils/sharedUtils");
898
898
const constants_1 = require ( "./utils/constants" ) ;
899
899
/**
900
900
* SQL Tools Plugin for importing diagrams from SQL DDL and exporting to SQL.
901
- * Version: 0.0.4
901
+ * Version: 0.0.5
902
902
*/
903
903
Draw . loadPlugin ( function ( ui ) {
904
904
// export sql methods
@@ -1035,7 +1035,6 @@ Draw.loadPlugin(function (ui) {
1035
1035
tableCell . insert ( rowCell ) ;
1036
1036
tableCell . geometry . height += 26 ;
1037
1037
}
1038
- rowCell = rowCell ;
1039
1038
}
1040
1039
;
1041
1040
function parseSql ( text , type ) {
@@ -1229,9 +1228,16 @@ Draw.loadPlugin(function (ui) {
1229
1228
} , { "./utils/constants" :5 , "./utils/sharedUtils" :6 , "@funktechno/little-mermaid-2-the-sql/lib/src/generate-sql-ddl" :1 , "@funktechno/sqlsimpleparser" :3 } ] , 5 :[ function ( require , module , exports ) {
1230
1229
"use strict" ;
1231
1230
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
1232
- exports . pluginVersion = void 0 ;
1231
+ exports . validEnumTypes = exports . enumKeyword = exports . formatKeyword = exports . commentColumnQuantifiers = exports . pluginVersion = void 0 ;
1233
1232
// export sql methods
1234
- exports . pluginVersion = "0.0.4" ;
1233
+ exports . pluginVersion = "0.0.5" ;
1234
+ exports . commentColumnQuantifiers = {
1235
+ Start : "/**" ,
1236
+ End : "*/" ,
1237
+ } ;
1238
+ exports . formatKeyword = "@format" ;
1239
+ exports . enumKeyword = "enum" ;
1240
+ exports . validEnumTypes = [ "string" , "number" , "integer" , "boolean" ] ;
1235
1241
1236
1242
} , { } ] , 6 :[ function ( require , module , exports ) {
1237
1243
"use strict" ;
@@ -1241,7 +1247,12 @@ exports.removeHtml = removeHtml;
1241
1247
exports . dbTypeEnds = dbTypeEnds ;
1242
1248
exports . RemoveNameQuantifiers = RemoveNameQuantifiers ;
1243
1249
exports . getDbLabel = getDbLabel ;
1250
+ exports . entityName = entityName ;
1251
+ exports . getCommentIndexes = getCommentIndexes ;
1244
1252
exports . getMermaidDiagramDb = getMermaidDiagramDb ;
1253
+ exports . GenerateDatabaseModel = GenerateDatabaseModel ;
1254
+ exports . generateComment = generateComment ;
1255
+ const constants_1 = require ( "./constants" ) ;
1245
1256
/**
1246
1257
* return text quantifiers for dialect
1247
1258
* @returns json
@@ -1307,6 +1318,34 @@ function getDbLabel(label, columnQuantifiers) {
1307
1318
} ;
1308
1319
return attribute ;
1309
1320
}
1321
+ function entityName ( description , format ) {
1322
+ let result = "" ;
1323
+ if ( description ) {
1324
+ result += `${ description } ` ;
1325
+ }
1326
+ if ( format ) {
1327
+ result += ` @format ${ format } ` ;
1328
+ }
1329
+ if ( result ) {
1330
+ result = result . trim ( ) ;
1331
+ result = `/** ${ result } */` ;
1332
+ }
1333
+ return result ;
1334
+ }
1335
+ function getCommentIndexes ( result ) {
1336
+ let hasComment = false ;
1337
+ if ( result . indexOf ( constants_1 . commentColumnQuantifiers . Start ) !== - 1 && result . indexOf ( constants_1 . commentColumnQuantifiers . End ) !== - 1 ) {
1338
+ hasComment = true ;
1339
+ }
1340
+ const beforeIndex = hasComment ? result . indexOf ( constants_1 . commentColumnQuantifiers . Start ) : - 1 ;
1341
+ const firstSpaceIndex = hasComment ? result . indexOf ( constants_1 . commentColumnQuantifiers . Start ) + constants_1 . commentColumnQuantifiers . Start . length : - 1 ;
1342
+ const lastSpaceIndex = hasComment ? result . indexOf ( constants_1 . commentColumnQuantifiers . End ) - 1 : - 1 ;
1343
+ return {
1344
+ beforeStart : beforeIndex ,
1345
+ start : firstSpaceIndex ,
1346
+ end : lastSpaceIndex
1347
+ } ;
1348
+ }
1310
1349
/**
1311
1350
* generate db from drawio graph models
1312
1351
* @param ui
@@ -1319,16 +1358,43 @@ function getMermaidDiagramDb(ui, type) {
1319
1358
// only difference is entities is an array rather than object to allow duplicate tables
1320
1359
const entities = { } ;
1321
1360
const relationships = [ ] ;
1361
+ // TODO: support for ts and openapi enum
1322
1362
// build models
1323
1363
for ( const key in model . cells ) {
1324
1364
if ( Object . hasOwnProperty . call ( model . cells , key ) ) {
1325
1365
const mxcell = model . cells [ key ] ;
1326
1366
if ( mxcell . mxObjectId . indexOf ( "mxCell" ) !== - 1 ) {
1327
1367
if ( mxcell . style && mxcell . style . trim ( ) . startsWith ( "swimlane;" ) ) {
1368
+ let entityName = mxcell . value . toString ( ) ;
1369
+ let description = "" ;
1370
+ let formatValue = "" ;
1371
+ if ( ( entityName === null || entityName === void 0 ? void 0 : entityName . includes ( constants_1 . commentColumnQuantifiers . Start ) ) &&
1372
+ ( entityName === null || entityName === void 0 ? void 0 : entityName . includes ( constants_1 . commentColumnQuantifiers . End ) ) ) {
1373
+ let result = entityName . toString ( ) ;
1374
+ const commentIndexes = getCommentIndexes ( result ) ;
1375
+ const firstSpaceIndex = commentIndexes . start ;
1376
+ const lastSpaceIndex = commentIndexes . end ;
1377
+ entityName = result . substring ( 0 , commentIndexes . beforeStart ) ;
1378
+ result = result . substring ( firstSpaceIndex , lastSpaceIndex ) ;
1379
+ if ( result . indexOf ( constants_1 . formatKeyword ) !== - 1 ) {
1380
+ const formatIndex = result . indexOf ( constants_1 . formatKeyword ) ;
1381
+ formatValue = result . substring ( formatIndex + constants_1 . formatKeyword . length ) . trim ( ) ;
1382
+ result = result . substring ( 0 , formatIndex ) ;
1383
+ }
1384
+ if ( result ) {
1385
+ description = result ;
1386
+ }
1387
+ // decription = attribute.attributeType?.replace("/**", "").replace("*/", "");
1388
+ }
1328
1389
const entity = {
1329
- name : RemoveNameQuantifiers ( mxcell . value ) ,
1390
+ name : RemoveNameQuantifiers ( entityName ) ,
1330
1391
attributes : [ ] ,
1331
1392
} ;
1393
+ const comment = generateComment ( description , formatValue ) ;
1394
+ if ( comment ) {
1395
+ entity . name += comment ;
1396
+ }
1397
+ // const comment =
1332
1398
for ( let c = 0 ; c < mxcell . children . length ; c ++ ) {
1333
1399
const col = mxcell . children [ c ] ;
1334
1400
if ( col . mxObjectId . indexOf ( "mxCell" ) !== - 1 ) {
@@ -1482,6 +1548,10 @@ function getMermaidDiagramDb(ui, type) {
1482
1548
}
1483
1549
}
1484
1550
}
1551
+ const db = GenerateDatabaseModel ( entities , relationships ) ;
1552
+ return db ;
1553
+ }
1554
+ function GenerateDatabaseModel ( entities , relationships ) {
1485
1555
class DatabaseModel {
1486
1556
constructor ( entities , relationships ) {
1487
1557
this . entities = entities ;
@@ -1497,5 +1567,19 @@ function getMermaidDiagramDb(ui, type) {
1497
1567
const db = new DatabaseModel ( entities , relationships ) ;
1498
1568
return db ;
1499
1569
}
1570
+ function generateComment ( description , formatValue ) {
1571
+ let result = "" ;
1572
+ if ( description ) {
1573
+ result += `${ description } ` ;
1574
+ }
1575
+ if ( formatValue ) {
1576
+ result += ` @format ${ formatValue } ` ;
1577
+ }
1578
+ if ( result ) {
1579
+ result = result . trim ( ) ;
1580
+ result = `${ constants_1 . commentColumnQuantifiers . Start } ${ result } ${ constants_1 . commentColumnQuantifiers . End } ` ;
1581
+ }
1582
+ return result ;
1583
+ }
1500
1584
1501
- } , { } ] } , { } , [ 4 ] ) ;
1585
+ } , { "./constants" : 5 } ] } , { } , [ 4 ] ) ;
0 commit comments