Skip to content

Commit

Permalink
Delete if it ends with a comma
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkiu committed Sep 18, 2022
1 parent 9ea6324 commit 7891602
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dist/main.cjs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/main.mjs

Large diffs are not rendered by default.

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.7",
"version": "1.2.8",
"description": "Generate ERD UML file from Schema DDL file",
"type": "module",
"main": "dist/main.cjs",
Expand Down
5 changes: 2 additions & 3 deletions src/parse_ddl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function _removeFunctionKeyword(sqlStr, functionKeyword) {
}
}
}
assert(removalEnd, 'Not detect removal region');
assert(removalEnd, `Not detect removal region - ${sqlStr}`);
removalSqlStr = removalSqlStr.slice(0, removalStart) + removalSqlStr.slice(removalEnd);
}
return removalSqlStr;
Expand Down Expand Up @@ -83,8 +83,7 @@ function _splitDdl(sqlStr) {
}
const end = restSqlStr.indexOf(';', start) + 1;
const ddlStr = restSqlStr.substring(start, end);
// console.log(ddlStr.replace(/(\r\n|\n|\r)/g, '').replace(/\s+/g, ' '));
ddls.push(_removeUnparsableToken(ddlStr));
ddls.push(_removeUnparsableToken(ddlStr).replace(/,[\n\r\s]+\)/gm, '\n)'));
offset += end;
}
return ddls;
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"],
"match-token": ["VIRTUAL", "type = innodb", "default 0000-00-00 00:00:00", "default 0000-00-00", "CONSTRANT check_active"],
"function": ["GENERATED", "CHECK", "PARTITION BY LIST (transaction_type)"]
}
7 changes: 0 additions & 7 deletions test/schema_to_erd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ 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 7891602

Please sign in to comment.