Skip to content

Commit

Permalink
HCK-8896: Refactor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightlngale committed Nov 29, 2024
1 parent 50f02de commit 8646e27
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const hydrateAlterView = _ => view => {
* */
const getAddViewsScripts = (provider, _) => view => {
const hydratedView = hydrateView(_)(view);
const script = provider.createView({ _, ...hydratedView });
const script = provider.createView(hydratedView);

return {
isActivated: true,
Expand Down Expand Up @@ -137,7 +137,7 @@ const getModifyViewsScripts = (provider, _, dbVersion) => view => {
}
const dropViewScript = provider.dropView(viewName);
const hydratedView = hydrateView(_)(view);
const addViewScript = provider.createView({ _, ...hydratedView });
const addViewScript = provider.createView(hydratedView);
const dropViewScriptDto = AlterScriptDto.getInstance([dropViewScript], true, true);
const addViewScriptDto = AlterScriptDto.getInstance([addViewScript], true, false);

Expand Down
2 changes: 0 additions & 2 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ module.exports = {
* */
generateViewScript(data, logger, callback, app) {
try {
const _ = app.require('lodash');
const provider = require('./ddlProvider/ddlProvider')(app);
const viewSchema = JSON.parse(data.jsonSchema || '{}');
const dbVersion = data.modelData[0].dbVersion;
Expand All @@ -268,7 +267,6 @@ module.exports = {
const databaseStatement = getDatabaseStatement(data.containerData, isUnityCatalogSupports, dbVersion);

const script = provider.createView({
_,
schema: viewSchema,
viewData: data.viewData,
containerData: data.containerData,
Expand Down
13 changes: 8 additions & 5 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getContainerName,
getEntityData,
getEntityProperties,
wrapInBrackets,
} = require('../utils/general');
const { getViewTagsStatement } = require('../helpers/unityTagsHelper');
const { getTablePropertiesClause } = require('../helpers/tableHelper');
Expand All @@ -22,7 +23,7 @@ module.exports = app => {
},

createView(data) {
const { _, schema, viewData, containerData, collectionRefsDefinitionsMap } = data;
const { schema, viewData, containerData, collectionRefsDefinitionsMap } = data;

const columns = schema.properties || {};
const view = _.first(viewData) || {};
Expand Down Expand Up @@ -51,20 +52,22 @@ module.exports = app => {
temporary: isTemporary ? ' TEMPORARY' : '',
ifNotExists: ifNotExists ? ' IF NOT EXISTS' : '',
name,
columnList: view.columnList ? `\n(${view.columnList})` : viewHelper.getDefaultColumnList(columns),
columnList: view.columnList
? `${wrapInBrackets(view.columnList)}`
: viewHelper.getDefaultColumnList(columns),
schemaBinding: '',
comment: viewHelper.getCommentStatement(schema.description),
tablePropertyStatements: tableProperties.length
? `\nTBLPROPERTIES (${getTablePropertiesClause(_)(tableProperties)})`
? `TBLPROPERTIES (${getTablePropertiesClause(_)(tableProperties)})`
: '',
query: schema.selectStatement
? `\nAS ${schema.selectStatement}`
? `AS ${schema.selectStatement}`
: viewHelper.getTableSelectStatement({
_,
collectionRefsDefinitionsMap,
columns,
}),
viewUnityTagsStatements: viewUnityTagsStatements ? `\n${viewUnityTagsStatements};` : '',
viewUnityTagsStatements: viewUnityTagsStatements ? `${viewUnityTagsStatements};` : '',
});
},

Expand Down
1 change: 0 additions & 1 deletion forward_engineering/helpers/feScriptBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const getContainerLevelViewScriptDtos = (data, provider, _) => {
const viewSchema = JSON.parse(data.jsonSchema[viewId] || '{}');
const viewData = data.viewData[viewId];
const viewScript = provider.createView({
_,
schema: viewSchema,
viewData: viewData,
containerData: data.containerData,
Expand Down
4 changes: 2 additions & 2 deletions forward_engineering/helpers/viewHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ function getDefaultColumnList(properties) {
})
.join(',\n');

return list ? `\n(${list}\n)` : '';
return list ? `(${list})` : '';
}

function getTableSelectStatement({ _, collectionRefsDefinitionsMap, columns }) {
const fromStatement = getFromStatement(_)(collectionRefsDefinitionsMap, columns);
const columnsNames = getColumnNames(_)(collectionRefsDefinitionsMap, columns);

if (fromStatement && columnsNames?.length) {
return `\nAS SELECT ${joinColumnNames(columnsNames)}\n${fromStatement}`;
return `AS SELECT ${joinColumnNames(columnsNames)}\n${fromStatement}`;
}

return '';
Expand Down

0 comments on commit 8646e27

Please sign in to comment.