Skip to content

Commit 6c671c5

Browse files
authored
Merge pull request #23 from funktechno/dev
v 0.0.3
2 parents 73b8ade + a3253ec commit 6c671c5

File tree

12 files changed

+216392
-4898
lines changed

12 files changed

+216392
-4898
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
],
66
"parserOptions": {
77
"ecmaVersion": 2018,
8+
"allowImportExportEverywhere": true,
89
"sourceType": "module"
910
},
1011
"rules": {
@@ -20,6 +21,9 @@
2021
"@typescript-eslint/camelcase": "off",
2122
"@typescript-eslint/no-explicit-any": "off",
2223
"no-multiple-empty-lines": "error",
24+
"no-use-before-define": "off",
25+
"@typescript-eslint/no-non-null-assertion": "off",
26+
"@typescript-eslint/no-use-before-define": "off",
2327
"@typescript-eslint/no-inferrable-types": [
2428
"warn",
2529
{

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ jobs:
2020
- run: npm ci
2121
- run: npm test
2222
- run: npm run build:client
23+
- run: npm run build:client:nosql
24+
- run: npm run build:client:nosql:min

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# sqltooling-drawio
2-
plugins for sql tooling in drawio
2+
* 3rd party plugins for sql tooling in drawio
3+
* contributions welcome
34

45
## Getting Started
56
* see https://github.com/ariel-bentu/tam-drawio for multiple install options
67
* download plugin file
7-
* [sql.js](https://raw.githubusercontent.com/funktechno/sqltooling-drawio/main/dist/sql.js)
8+
* [sql.js](https://raw.githubusercontent.com/funktechno/sqltooling-drawio/main/dist/sql.js) - import/export SQL DLLS
9+
* [nosql.js](https://raw.githubusercontent.com/funktechno/sqltooling-drawio/main/dist/nosql.js) - import/export typescript interfaces and openapi jsons (NOT vscode compatible)
10+
* or [nosql.min.js](https://raw.githubusercontent.com/funktechno/sqltooling-drawio/main/dist/nosql.min.js)
811
* or clone project `git clone --branch main git@github.com:funktechno/sqltooling-drawio.git` and check `dist folder`
912
* vscode [Draw.io Integration](https://marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio)
1013
* settings.json
@@ -21,4 +24,5 @@ plugins for sql tooling in drawio
2124

2225
## Development
2326
* `npm install`
24-
* `npm build:client` to update `dist/sql.js`
27+
* `npm build:client` to update `dist/sql.js`
28+
* `npm build:client:nosql` to update `dist/nosql.js`

build/updateVersion.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ console.log("Updating to version " + package.version);
1313
files.forEach((file) => {
1414
const filePath = `${directoryPath}/${file}`;
1515
let content = fs.readFileSync(filePath, "utf8");
16+
let updated = false;
1617
while(content.includes(oldText)) {
18+
updated = true
1719
content = content.replace(oldText, package.version);
1820
}
19-
// content = content.replace(new RegExp(oldText, "g"), newText);
20-
fs.writeFileSync(filePath, content, "utf8");
21-
console.log(`Replaced text in ${file}`);
21+
if(updated) {
22+
// content = content.replace(new RegExp(oldText, "g"), newText);
23+
fs.writeFileSync(filePath, content, "utf8");
24+
console.log(`Replaced text in ${file}`);
25+
}
2226
});

dist/nosql.js

Lines changed: 201657 additions & 0 deletions
Large diffs are not rendered by default.

dist/nosql.min.js

Lines changed: 449 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sql.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,11 @@ const generate_sql_ddl_1 = require("@funktechno/little-mermaid-2-the-sql/lib/src
896896
const sqlsimpleparser_1 = require("@funktechno/sqlsimpleparser");
897897
/**
898898
* SQL Tools Plugin for importing diagrams from SQL DDL and exporting to SQL.
899-
* Version: 0.0.2
899+
* Version: 0.0.3
900900
*/
901901
Draw.loadPlugin(function (ui) {
902902
// export sql methods
903-
const pluginVersion = "0.0.2";
903+
const pluginVersion = "0.0.3";
904904
//Create Base div
905905
const divGenSQL = document.createElement("div");
906906
divGenSQL.style.userSelect = "none";
@@ -1043,14 +1043,14 @@ Draw.loadPlugin(function (ui) {
10431043
// has to be one to many and not one to one
10441044
if ((targetIsPrimary || sourceIsPrimary) &&
10451045
!(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);
10481048
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);
10521052
targetId = targetAttr.attributeName;
1053-
var targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
1053+
const targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
10541054
// entityA primary
10551055
// entityB foreign
10561056
const relationship = {
@@ -1067,23 +1067,23 @@ Draw.loadPlugin(function (ui) {
10671067
`[${targetEntity}.${targetId}] to [${sourceEntity}.${sourceId}]`
10681068
};
10691069
// 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);
10711071
if (exists == -1) {
10721072
relationships.push(relationship);
10731073
}
10741074
}
10751075
else if (targetIsPrimary && sourceIsPrimary) {
10761076
// 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);
10791079
sourceAttr.attributeKeyType = "PK";
10801080
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);
10841084
targetAttr.attributeKeyType = "PK";
10851085
targetId = targetAttr.attributeName;
1086-
var targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
1086+
const targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
10871087
const compositeEntity = {
10881088
name: RemoveNameQuantifiers(sourceEntity) + "_" + RemoveNameQuantifiers(targetEntity),
10891089
attributes: [sourceAttr, targetAttr]
@@ -1109,7 +1109,7 @@ Draw.loadPlugin(function (ui) {
11091109
roleA: `[${sourceEntity}.${sourceId}] to [${compositeEntity.name}.${sourceId}]`
11101110
};
11111111
// 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);
11131113
if (exists == -1) {
11141114
relationships.push(relationship);
11151115
}
@@ -1179,7 +1179,7 @@ Draw.loadPlugin(function (ui) {
11791179
// update sql value in text area
11801180
sqlInputGenSQL.value = sql;
11811181
// TODO: use selection as well?
1182-
const modelSelected = ui.editor.graph.getSelectionModel();
1182+
// const modelSelected = ui.editor.graph.getSelectionModel();
11831183
}
11841184
;
11851185
mxUtils.br(divGenSQL);
@@ -1238,18 +1238,16 @@ Draw.loadPlugin(function (ui) {
12381238
divFromSQL.style.overflow = "hidden";
12391239
divFromSQL.style.padding = "10px";
12401240
divFromSQL.style.height = "100%";
1241-
var graph = ui.editor.graph;
12421241
const sqlInputFromSQL = document.createElement("textarea");
12431242
sqlInputFromSQL.style.height = "200px";
12441243
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" +
12471246
"CREATE TABLE Orders\n(\n OrderID int NOT NULL PRIMARY KEY,\n PersonID int NOT NULL,\n FOREIGN KEY ([PersonID]) REFERENCES [Persons]([PersonID])" +
12481247
"\n);`;
12491248
sqlInputFromSQL.value = defaultReset;
12501249
mxUtils.br(divFromSQL);
12511250
divFromSQL.appendChild(sqlInputFromSQL);
1252-
var graph = ui.editor.graph;
12531251
// Extends Extras menu
12541252
mxResources.parse("fromSql=From SQL");
12551253
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) {
13351333
// add foreign key edges
13361334
const model = graph.getModel();
13371335
const columnQuantifiers = GetColumnQuantifiers(type);
1338-
const pt = graph.getFreeInsertPoint();
1336+
// const pt = graph.getFreeInsertPoint();
13391337
foreignKeyList.forEach(function (fk) {
13401338
if (fk.IsDestination && fk.PrimaryKeyName && fk.ReferencesPropertyName &&
13411339
fk.PrimaryKeyTableName && fk.ReferencesTableName) {
@@ -1446,7 +1444,7 @@ Draw.loadPlugin(function (ui) {
14461444
};
14471445
}
14481446
if (theMenuExportAs && !window.VsCodeApi) {
1449-
var oldMenuExportAs = theMenuExportAs.funct;
1447+
const oldMenuExportAs = theMenuExportAs.funct;
14501448
theMenuExportAs.funct = function (...args) {
14511449
const [menu, parent] = args;
14521450
oldMenuExportAs.apply(this, args);
@@ -1457,7 +1455,7 @@ Draw.loadPlugin(function (ui) {
14571455
// vscode file export sql menu
14581456
const menu = ui.menus.get("file");
14591457
if (menu && menu.enabled) {
1460-
var oldMenuExportAs = menu.funct;
1458+
const oldMenuExportAs = menu.funct;
14611459
menu.funct = function (...args) {
14621460
const [menu, parent] = args;
14631461
oldMenuExportAs.apply(this, args);

gulpfile.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import gulp from "gulp";
2+
import browserify from "browserify";
3+
import source from "vinyl-source-stream";
4+
// import tsify from "tsify";
5+
import buffer from "vinyl-buffer";
6+
import babelify from "babelify";
7+
import sourcemaps from "gulp-sourcemaps";
8+
import gutil from "gulp-util";
9+
import uglify from "gulp-uglify";
10+
import rename from "gulp-rename";
11+
12+
gulp.task("default", () => {
13+
return browserify({
14+
basedir: ".",
15+
debug: true,
16+
entries: ["src/nosql.ts"], // Your entry point(s)
17+
cache: {},
18+
packageCache: {}
19+
})
20+
.plugin("tsify", { target: "es2016"}) // TypeScript plugin
21+
.transform(babelify.configure({
22+
presets: ["es2015"]
23+
}))
24+
// .transform(babelify, { presets: ["@babel/preset-env"], extensions: [".ts"] }) // Babelify with ES6+ presets
25+
.bundle()
26+
.pipe(source("nosql.js")) // Output filename
27+
.pipe(buffer())
28+
.pipe(sourcemaps.init({ loadMaps: true }))
29+
.pipe(uglify()) // Minify (optional)
30+
.pipe(rename({ suffix: ".min" })) // Add ".min" to the filename
31+
.on("error", gutil.log)
32+
// .pipe(sourcemaps.write("./", {}))
33+
.pipe(gulp.dest("dist")); // Output directory
34+
});

0 commit comments

Comments
 (0)