Skip to content

Commit

Permalink
Merge pull request #119 from SAP-samples/Feb2024
Browse files Browse the repository at this point in the history
New sql append feature for table conversion and inspection
  • Loading branch information
jung-thomas committed Feb 16, 2024
2 parents e614b31 + e15c709 commit ad0bede
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"date": "2024-02-16",
"version": "3.202402.2",
"Changed": [
"Mass Convert of Tables to CDS if you use Pure Catalog Definitions, it will output sql append content",
"Table inspect to CDS if you choose no Persistence Exists, it will output sql append content"

]
},
{
"date": "2024-02-03",
"version": "3.202402.1",
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [3.202402.2] - 2024-02-16

**Changed**

- Mass Convert of Tables to CDS if you use Pure Catalog Definitions, it will output sql append content
- Table inspect to CDS if you choose no Persistence Exists, it will output sql append content

## [3.202402.1] - 2024-02-03

**Changed**
Expand Down
17 changes: 12 additions & 5 deletions bin/inspectTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export const builder = base.getBuilder({
default: false
},
noColons: {
type: 'boolean',
default: false,
desc: base.bundle.getText("noColons")
type: 'boolean',
default: false,
desc: base.bundle.getText("noColons")
}
})

Expand Down Expand Up @@ -86,7 +86,7 @@ export let inputPrompts = {
noColons: {
type: 'boolean',
description: base.bundle.getText("noColons")
}
}
}

export function handler(argv) {
Expand All @@ -100,7 +100,7 @@ export async function tableInspect(prompts) {
import('json-to-pretty-yaml'),
import('odata2openapi')
])

try {
base.setPrompts(prompts)
let dbConnection = await conn.createConnection(prompts, false)
Expand Down Expand Up @@ -153,6 +153,13 @@ export async function tableInspect(prompts) {
}
case 'cds': {
let cdsSource = await dbInspect.formatCDS(db, object, fields, constraints, "table", schema, null)
if (!dbInspect.options.useExists) {
let output = await dbInspect.getDef(db, schema, prompts.table)
output = output.slice(7)
const lastParenthesisIndex = output.lastIndexOf(')')
const substringAfterLastParenthesis = output.substring(lastParenthesisIndex + 1)
cdsSource = `@sql.append: \`\`\`sql \n${substringAfterLastParenthesis}\n\`\`\`\n${cdsSource}`
}
results.cds = cdsSource
console.log(highlight(cdsSource))
break
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hana-cli",
"version": "3.202402.1",
"version": "3.202402.2",
"description": "HANA Developer Command Line Interface",
"main": "index.js",
"bin": {
Expand Down
14 changes: 11 additions & 3 deletions utils/massConvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async function hdbtableViews(prompts, viewResults, wss, db, schema, replacer, zi
let object = await dbInspect.getView(db, schema, view.VIEW_NAME)
let fields = []
if (await dbInspect.isCalculationView(db, schema, view.VIEW_NAME)) {
fields = await dbInspect.getCalcViewFields(db, schema, view.VIEW_NAME, object[0].VIEW_OID)
fields = await dbInspect.getCalcViewFields(db, schema, view.VIEW_NAME, object[0].VIEW_OID)
} else {
fields = await dbInspect.getViewFields(db, object[0].VIEW_OID)
}
Expand Down Expand Up @@ -358,6 +358,13 @@ async function cdsTables(prompts, results, wss, db, schema, cdsSource, logOutput
let constraints = await dbInspect.getConstraints(db, object)
cdsSource += await dbInspect.formatCDS(db, object, fields, constraints, "table", schema, null) + '\n'

if (dbInspect.options.userCatalogPure) {
let output = await dbInspect.getDef(db, schema, table.TABLE_NAME)
output = output.slice(7)
const lastParenthesisIndex = output.lastIndexOf(')')
const substringAfterLastParenthesis = output.substring(lastParenthesisIndex + 1)
cdsSource = `@sql.append: \`\`\`sql \n${substringAfterLastParenthesis}\n\`\`\`\n${cdsSource}`
}
progressBar.itemDone(table.TABLE_NAME)
logOutput.push({ object: table.TABLE_NAME, status: 'Success' })
}
Expand Down Expand Up @@ -405,7 +412,7 @@ async function cdsViews(prompts, viewResults, wss, db, schema, cdsSource, logOut
parameters = await dbInspect.getCalcViewParameters(db, schema, view.VIEW_NAME, object[0].VIEW_OID)
} else {
fields = await dbInspect.getViewFields(db, object[0].VIEW_OID)
parameters = await dbInspect.getViewParameters(db, object[0].VIEW_OID)
parameters = await dbInspect.getViewParameters(db, object[0].VIEW_OID)
}
cdsSource += await dbInspect.formatCDS(db, object, fields, null, "view", schema, null, parameters)

Expand Down Expand Up @@ -561,6 +568,7 @@ export async function convert(wss) {
dbInspect.options.useExists = prompts.useExists
dbInspect.options.useQuoted = prompts.useQuoted
dbInspect.options.log = prompts.log
dbInspect.options.userCatalogPure = prompts.useCatalogPure


let logOutput = []
Expand Down Expand Up @@ -609,7 +617,7 @@ export async function convert(wss) {
prompts, viewResults, wss, db, schema, cdsSource, logOutput
)
await writeCDS(prompts, wss, cdsSource, logOutput)
await writeSynonyms(prompts, wss)
await writeSynonyms(prompts, wss)
break
}
}
Expand Down

0 comments on commit ad0bede

Please sign in to comment.