Skip to content

Commit

Permalink
Simplify function removal code
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkiu committed Sep 18, 2022
1 parent 66b7035 commit 9ea6324
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
25 changes: 12 additions & 13 deletions dist/main.cjs

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions dist/main.mjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "schema-to-erd",
"version": "1.2.6",
"version": "1.2.7",
"description": "Generate ERD UML file from Schema DDL file",
"type": "module",
"main": "dist/main.cjs",
Expand Down
5 changes: 1 addition & 4 deletions src/parse_ddl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ function _removeFunctionKeyword(sqlStr, functionKeyword) {
parenthesesDepth += 1;
} else if (c === ')') {
parenthesesDepth -= 1;
assert(parenthesesDepth >= 0, `parenthesesDepth(${parenthesesDepth}) is minus value`);
if (parenthesesDepth === 0) {
removalEnd = i+1;
break;
}
}
if (c === '\n' && removalEnd && parenthesesDepth === 0) {
break;
}
}
assert(removalEnd, 'Not detect removal region');
removalSqlStr = removalSqlStr.slice(0, removalStart) + removalSqlStr.slice(removalEnd);
Expand Down
2 changes: 1 addition & 1 deletion src/unparsable_token.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"inter-token": ["BINARY", "national", "STORED"],
"match-token": ["VIRTUAL", "type = innodb", "default 0000-00-00 00:00:00", "default 0000-00-00"],
"function": ["GENERATED", "CHECK", "PARTITION"]
"function": ["GENERATED", "CHECK", "PARTITION BY LIST (transaction_type)"]
}
7 changes: 7 additions & 0 deletions test/schema_to_erd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const fileList = await getSqlFiles('schema_samples/**/*.sql');
console.log(fileList);

describe('samples', () => {
it('function.sql', async () => {
const pumlFilePath = await schemaToErd('./schema_samples/function.sql');
const { dir, base } = path.parse(pumlFilePath);
const pathParts = dir.split(path.sep);
const expectedFilePath = path.join('./puml_examples', ...pathParts.slice(1), base);
assert.ok(await compareFiles(pumlFilePath, expectedFilePath));
});
fileList.map((filePath) => {
it(path.parse(filePath).base, async () => {
const pumlFilePath = await schemaToErd(filePath);
Expand Down

0 comments on commit 9ea6324

Please sign in to comment.