-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCK-8697: Improve RE of partitions (#88)
* HCK-8697: added improed query draft * Created module for reusable query * Added missing line break * Applied reusable nested query * Added missing argument * Fixed formatting * Fixed formatting * Fixed formatting * HCK-8697: handle no items selection case --------- Co-authored-by: Thomas Jakemeyn <thomas.jakemeyn@gmail.com>
- Loading branch information
1 parent
11c81f8
commit df0a482
Showing
3 changed files
with
53 additions
and
16 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
33 changes: 33 additions & 0 deletions
33
reverse_engineering/queries/queryForRetrievingTheTablesSelectedByTheUser.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,33 @@ | ||
function buildPredicateForTable({ schema, table }) { | ||
return `(sch.name = '${schema}' AND tbl.name = '${table}')`; | ||
} | ||
|
||
function buildPredicateForTablesInSchema({ schema, tables }) { | ||
return tables.map(table => buildPredicateForTable({ schema, table })).join('OR'); | ||
} | ||
|
||
function queryForRetrievingTheTablesSelectedByTheUser({ schemaToTablesMap }) { | ||
const projection = { | ||
tableId: 'tableId', | ||
tableName: 'tableName', | ||
schemaName: 'schemaName', | ||
}; | ||
const predicate = Object.entries(schemaToTablesMap) | ||
.map(([schema, tables]) => buildPredicateForTablesInSchema({ schema, tables })) | ||
.join('OR'); | ||
const whereClause = Object.entries(schemaToTablesMap).length > 0 ? `WHERE ${predicate}` : ''; | ||
const sql = ` | ||
SELECT | ||
tbl.object_id AS ${projection.tableId} | ||
, tbl.name AS ${projection.tableName} | ||
, sch.name AS ${projection.schemaName} | ||
FROM sys.tables tbl | ||
JOIN sys.schemas sch ON sch.schema_id = tbl.schema_id | ||
${whereClause}`; | ||
return { | ||
projection, | ||
sql: () => sql, | ||
}; | ||
} | ||
|
||
module.exports = { queryForRetrievingTheTablesSelectedByTheUser }; |
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