Skip to content

Commit

Permalink
Merge pull request #23 from funktechno/dev
Browse files Browse the repository at this point in the history
v 0.0.3
  • Loading branch information
lastlink authored Jun 24, 2024
2 parents 73b8ade + a3253ec commit 6c671c5
Show file tree
Hide file tree
Showing 12 changed files with 216,392 additions and 4,898 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"parserOptions": {
"ecmaVersion": 2018,
"allowImportExportEverywhere": true,
"sourceType": "module"
},
"rules": {
Expand All @@ -20,6 +21,9 @@
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-multiple-empty-lines": "error",
"no-use-before-define": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-inferrable-types": [
"warn",
{
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
- run: npm ci
- run: npm test
- run: npm run build:client
- run: npm run build:client:nosql
- run: npm run build:client:nosql:min
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# sqltooling-drawio
plugins for sql tooling in drawio
* 3rd party plugins for sql tooling in drawio
* contributions welcome

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

## Development
* `npm install`
* `npm build:client` to update `dist/sql.js`
* `npm build:client` to update `dist/sql.js`
* `npm build:client:nosql` to update `dist/nosql.js`
10 changes: 7 additions & 3 deletions build/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ console.log("Updating to version " + package.version);
files.forEach((file) => {
const filePath = `${directoryPath}/${file}`;
let content = fs.readFileSync(filePath, "utf8");
let updated = false;
while(content.includes(oldText)) {
updated = true
content = content.replace(oldText, package.version);
}
// content = content.replace(new RegExp(oldText, "g"), newText);
fs.writeFileSync(filePath, content, "utf8");
console.log(`Replaced text in ${file}`);
if(updated) {
// content = content.replace(new RegExp(oldText, "g"), newText);
fs.writeFileSync(filePath, content, "utf8");
console.log(`Replaced text in ${file}`);
}
});
201,657 changes: 201,657 additions & 0 deletions dist/nosql.js

Large diffs are not rendered by default.

449 changes: 449 additions & 0 deletions dist/nosql.min.js

Large diffs are not rendered by default.

46 changes: 22 additions & 24 deletions dist/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,11 @@ const generate_sql_ddl_1 = require("@funktechno/little-mermaid-2-the-sql/lib/src
const sqlsimpleparser_1 = require("@funktechno/sqlsimpleparser");
/**
* SQL Tools Plugin for importing diagrams from SQL DDL and exporting to SQL.
* Version: 0.0.2
* Version: 0.0.3
*/
Draw.loadPlugin(function (ui) {
// export sql methods
const pluginVersion = "0.0.2";
const pluginVersion = "0.0.3";
//Create Base div
const divGenSQL = document.createElement("div");
divGenSQL.style.userSelect = "none";
Expand Down Expand Up @@ -1043,14 +1043,14 @@ Draw.loadPlugin(function (ui) {
// has to be one to many and not one to one
if ((targetIsPrimary || sourceIsPrimary) &&
!(targetIsPrimary && sourceIsPrimary)) {
var sourceId = edge.source.value;
var sourceAttr = getDbLabel(sourceId, columnQuantifiers);
let sourceId = edge.source.value;
const sourceAttr = getDbLabel(sourceId, columnQuantifiers);
sourceId = sourceAttr.attributeName;
var sourceEntity = RemoveNameQuantifiers(edge.source.parent.value);
var targetId = edge.target.value;
var targetAttr = getDbLabel(targetId, columnQuantifiers);
const sourceEntity = RemoveNameQuantifiers(edge.source.parent.value);
let targetId = edge.target.value;
const targetAttr = getDbLabel(targetId, columnQuantifiers);
targetId = targetAttr.attributeName;
var targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
const targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
// entityA primary
// entityB foreign
const relationship = {
Expand All @@ -1067,23 +1067,23 @@ Draw.loadPlugin(function (ui) {
`[${targetEntity}.${targetId}] to [${sourceEntity}.${sourceId}]`
};
// check that is doesn't already exist
var exists = relationships.findIndex(r => r.entityA == relationship.entityA && r.entityB == relationship.entityB && r.roleA == relationship.roleA);
const exists = relationships.findIndex(r => r.entityA == relationship.entityA && r.entityB == relationship.entityB && r.roleA == relationship.roleA);
if (exists == -1) {
relationships.push(relationship);
}
}
else if (targetIsPrimary && sourceIsPrimary) {
// add a new many to many table
var sourceId = edge.source.value;
sourceAttr = getDbLabel(sourceId, columnQuantifiers);
let sourceId = edge.source.value;
const sourceAttr = getDbLabel(sourceId, columnQuantifiers);
sourceAttr.attributeKeyType = "PK";
sourceId = sourceAttr.attributeName;
var sourceEntity = RemoveNameQuantifiers(edge.source.parent.value);
var targetId = edge.target.value;
targetAttr = getDbLabel(targetId, columnQuantifiers);
const sourceEntity = RemoveNameQuantifiers(edge.source.parent.value);
let targetId = edge.target.value;
const targetAttr = getDbLabel(targetId, columnQuantifiers);
targetAttr.attributeKeyType = "PK";
targetId = targetAttr.attributeName;
var targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
const targetEntity = RemoveNameQuantifiers(edge.target.parent.value);
const compositeEntity = {
name: RemoveNameQuantifiers(sourceEntity) + "_" + RemoveNameQuantifiers(targetEntity),
attributes: [sourceAttr, targetAttr]
Expand All @@ -1109,7 +1109,7 @@ Draw.loadPlugin(function (ui) {
roleA: `[${sourceEntity}.${sourceId}] to [${compositeEntity.name}.${sourceId}]`
};
// check that is doesn't already exist
var exists = relationships.findIndex(r => r.entityA == relationship.entityA && r.entityB == relationship.entityB && r.roleA == relationship.roleA);
let exists = relationships.findIndex(r => r.entityA == relationship.entityA && r.entityB == relationship.entityB && r.roleA == relationship.roleA);
if (exists == -1) {
relationships.push(relationship);
}
Expand Down Expand Up @@ -1179,7 +1179,7 @@ Draw.loadPlugin(function (ui) {
// update sql value in text area
sqlInputGenSQL.value = sql;
// TODO: use selection as well?
const modelSelected = ui.editor.graph.getSelectionModel();
// const modelSelected = ui.editor.graph.getSelectionModel();
}
;
mxUtils.br(divGenSQL);
Expand Down Expand Up @@ -1238,18 +1238,16 @@ Draw.loadPlugin(function (ui) {
divFromSQL.style.overflow = "hidden";
divFromSQL.style.padding = "10px";
divFromSQL.style.height = "100%";
var graph = ui.editor.graph;
const sqlInputFromSQL = document.createElement("textarea");
sqlInputFromSQL.style.height = "200px";
sqlInputFromSQL.style.width = "100%";
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 " +
"FirstName varchar(255),\n Address varchar(255),\n City varchar(255),\n Primary Key(PersonID)\n);\n\n" +
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 " +
"FirstName constchar(255),\n Address constchar(255),\n City constchar(255),\n Primary Key(PersonID)\n);\n\n" +
"CREATE TABLE Orders\n(\n OrderID int NOT NULL PRIMARY KEY,\n PersonID int NOT NULL,\n FOREIGN KEY ([PersonID]) REFERENCES [Persons]([PersonID])" +
"\n);`;
sqlInputFromSQL.value = defaultReset;
mxUtils.br(divFromSQL);
divFromSQL.appendChild(sqlInputFromSQL);
var graph = ui.editor.graph;
// Extends Extras menu
mxResources.parse("fromSql=From SQL");
const wndFromSQL = new mxWindow(mxResources.get("fromSql"), divFromSQL, document.body.offsetWidth - 480, 140, 320, 320, true, true);
Expand Down Expand Up @@ -1335,7 +1333,7 @@ Draw.loadPlugin(function (ui) {
// add foreign key edges
const model = graph.getModel();
const columnQuantifiers = GetColumnQuantifiers(type);
const pt = graph.getFreeInsertPoint();
// const pt = graph.getFreeInsertPoint();
foreignKeyList.forEach(function (fk) {
if (fk.IsDestination && fk.PrimaryKeyName && fk.ReferencesPropertyName &&
fk.PrimaryKeyTableName && fk.ReferencesTableName) {
Expand Down Expand Up @@ -1446,7 +1444,7 @@ Draw.loadPlugin(function (ui) {
};
}
if (theMenuExportAs && !window.VsCodeApi) {
var oldMenuExportAs = theMenuExportAs.funct;
const oldMenuExportAs = theMenuExportAs.funct;
theMenuExportAs.funct = function (...args) {
const [menu, parent] = args;
oldMenuExportAs.apply(this, args);
Expand All @@ -1457,7 +1455,7 @@ Draw.loadPlugin(function (ui) {
// vscode file export sql menu
const menu = ui.menus.get("file");
if (menu && menu.enabled) {
var oldMenuExportAs = menu.funct;
const oldMenuExportAs = menu.funct;
menu.funct = function (...args) {
const [menu, parent] = args;
oldMenuExportAs.apply(this, args);
Expand Down
34 changes: 34 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import gulp from "gulp";
import browserify from "browserify";
import source from "vinyl-source-stream";
// import tsify from "tsify";
import buffer from "vinyl-buffer";
import babelify from "babelify";
import sourcemaps from "gulp-sourcemaps";
import gutil from "gulp-util";
import uglify from "gulp-uglify";
import rename from "gulp-rename";

gulp.task("default", () => {
return browserify({
basedir: ".",
debug: true,
entries: ["src/nosql.ts"], // Your entry point(s)
cache: {},
packageCache: {}
})
.plugin("tsify", { target: "es2016"}) // TypeScript plugin
.transform(babelify.configure({
presets: ["es2015"]
}))
// .transform(babelify, { presets: ["@babel/preset-env"], extensions: [".ts"] }) // Babelify with ES6+ presets
.bundle()
.pipe(source("nosql.js")) // Output filename
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify()) // Minify (optional)
.pipe(rename({ suffix: ".min" })) // Add ".min" to the filename
.on("error", gutil.log)
// .pipe(sourcemaps.write("./", {}))
.pipe(gulp.dest("dist")); // Output directory
});
Loading

0 comments on commit 6c671c5

Please sign in to comment.