-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCK-7990: Fix splitting of column statements when deactivating the la…
…st one (#31) <!--do not remove this marker, its needed to replace info when ticket title is updated --> <!--jira-description-action-hidden-marker-start--> <table> <td> <a href="https://hackolade.atlassian.net/browse/HCK-7990" title="HCK-7990" target="_blank"><img alt="Sub-bug" src="https://hackolade.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium" />HCK-7990</a> [DB2]: DDL script is not valid when the last attribute is commented in Table </td></table> <br /> <!--jira-description-action-hidden-marker-end-->
- Loading branch information
1 parent
52ef9b8
commit 320148a
Showing
5 changed files
with
70 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
forward_engineering/utils/joinActivatedAndDeactivatedStatements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { INLINE_COMMENT } = require('../../constants/constants'); | ||
|
||
/** | ||
* @param {{ | ||
* index: number; | ||
* numberOfStatements: number; | ||
* lastIndexOfActivatedStatement: number; | ||
* delimiter: string; | ||
* }} | ||
* @return {string} | ||
* */ | ||
const getDelimiter = ({ index, numberOfStatements, lastIndexOfActivatedStatement, delimiter }) => { | ||
const isLastStatement = index === numberOfStatements - 1; | ||
const isLastActivatedStatement = index === lastIndexOfActivatedStatement; | ||
|
||
if (isLastStatement) { | ||
return ''; | ||
} | ||
|
||
if (isLastActivatedStatement) { | ||
return ' --' + delimiter; | ||
} | ||
|
||
return delimiter; | ||
}; | ||
|
||
/** | ||
* @param {{ | ||
* statements: string[]; | ||
* delimiter?: string; | ||
* indent?: string; | ||
* }} | ||
* @return {string} | ||
* */ | ||
const joinActivatedAndDeactivatedStatements = ({ statements, delimiter = ',', indent = '\n' }) => { | ||
const lastIndexOfActivatedStatement = statements.findLastIndex(statement => !statement.startsWith(INLINE_COMMENT)); | ||
const numberOfStatements = statements.length; | ||
|
||
return statements | ||
.map((statement, index) => { | ||
const currentDelimiter = getDelimiter({ | ||
index, | ||
numberOfStatements, | ||
lastIndexOfActivatedStatement, | ||
delimiter, | ||
}); | ||
|
||
return statement + currentDelimiter; | ||
}) | ||
.join(indent); | ||
}; | ||
|
||
module.exports = { | ||
joinActivatedAndDeactivatedStatements, | ||
}; |