Skip to content

Commit ad0bede

Browse files
authored
Merge pull request #119 from SAP-samples/Feb2024
New sql append feature for table conversion and inspection
2 parents e614b31 + e15c709 commit ad0bede

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

CHANGELOG.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
[
2+
{
3+
"date": "2024-02-16",
4+
"version": "3.202402.2",
5+
"Changed": [
6+
"Mass Convert of Tables to CDS if you use Pure Catalog Definitions, it will output sql append content",
7+
"Table inspect to CDS if you choose no Persistence Exists, it will output sql append content"
8+
9+
]
10+
},
211
{
312
"date": "2024-02-03",
413
"version": "3.202402.1",

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

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

7+
## [3.202402.2] - 2024-02-16
8+
9+
**Changed**
10+
11+
- Mass Convert of Tables to CDS if you use Pure Catalog Definitions, it will output sql append content
12+
- Table inspect to CDS if you choose no Persistence Exists, it will output sql append content
13+
714
## [3.202402.1] - 2024-02-03
815

916
**Changed**

bin/inspectTable.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export const builder = base.getBuilder({
4848
default: false
4949
},
5050
noColons: {
51-
type: 'boolean',
52-
default: false,
53-
desc: base.bundle.getText("noColons")
51+
type: 'boolean',
52+
default: false,
53+
desc: base.bundle.getText("noColons")
5454
}
5555
})
5656

@@ -86,7 +86,7 @@ export let inputPrompts = {
8686
noColons: {
8787
type: 'boolean',
8888
description: base.bundle.getText("noColons")
89-
}
89+
}
9090
}
9191

9292
export function handler(argv) {
@@ -100,7 +100,7 @@ export async function tableInspect(prompts) {
100100
import('json-to-pretty-yaml'),
101101
import('odata2openapi')
102102
])
103-
103+
104104
try {
105105
base.setPrompts(prompts)
106106
let dbConnection = await conn.createConnection(prompts, false)
@@ -153,6 +153,13 @@ export async function tableInspect(prompts) {
153153
}
154154
case 'cds': {
155155
let cdsSource = await dbInspect.formatCDS(db, object, fields, constraints, "table", schema, null)
156+
if (!dbInspect.options.useExists) {
157+
let output = await dbInspect.getDef(db, schema, prompts.table)
158+
output = output.slice(7)
159+
const lastParenthesisIndex = output.lastIndexOf(')')
160+
const substringAfterLastParenthesis = output.substring(lastParenthesisIndex + 1)
161+
cdsSource = `@sql.append: \`\`\`sql \n${substringAfterLastParenthesis}\n\`\`\`\n${cdsSource}`
162+
}
156163
results.cds = cdsSource
157164
console.log(highlight(cdsSource))
158165
break

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hana-cli",
3-
"version": "3.202402.1",
3+
"version": "3.202402.2",
44
"description": "HANA Developer Command Line Interface",
55
"main": "index.js",
66
"bin": {

utils/massConvert.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async function hdbtableViews(prompts, viewResults, wss, db, schema, replacer, zi
205205
let object = await dbInspect.getView(db, schema, view.VIEW_NAME)
206206
let fields = []
207207
if (await dbInspect.isCalculationView(db, schema, view.VIEW_NAME)) {
208-
fields = await dbInspect.getCalcViewFields(db, schema, view.VIEW_NAME, object[0].VIEW_OID)
208+
fields = await dbInspect.getCalcViewFields(db, schema, view.VIEW_NAME, object[0].VIEW_OID)
209209
} else {
210210
fields = await dbInspect.getViewFields(db, object[0].VIEW_OID)
211211
}
@@ -358,6 +358,13 @@ async function cdsTables(prompts, results, wss, db, schema, cdsSource, logOutput
358358
let constraints = await dbInspect.getConstraints(db, object)
359359
cdsSource += await dbInspect.formatCDS(db, object, fields, constraints, "table", schema, null) + '\n'
360360

361+
if (dbInspect.options.userCatalogPure) {
362+
let output = await dbInspect.getDef(db, schema, table.TABLE_NAME)
363+
output = output.slice(7)
364+
const lastParenthesisIndex = output.lastIndexOf(')')
365+
const substringAfterLastParenthesis = output.substring(lastParenthesisIndex + 1)
366+
cdsSource = `@sql.append: \`\`\`sql \n${substringAfterLastParenthesis}\n\`\`\`\n${cdsSource}`
367+
}
361368
progressBar.itemDone(table.TABLE_NAME)
362369
logOutput.push({ object: table.TABLE_NAME, status: 'Success' })
363370
}
@@ -405,7 +412,7 @@ async function cdsViews(prompts, viewResults, wss, db, schema, cdsSource, logOut
405412
parameters = await dbInspect.getCalcViewParameters(db, schema, view.VIEW_NAME, object[0].VIEW_OID)
406413
} else {
407414
fields = await dbInspect.getViewFields(db, object[0].VIEW_OID)
408-
parameters = await dbInspect.getViewParameters(db, object[0].VIEW_OID)
415+
parameters = await dbInspect.getViewParameters(db, object[0].VIEW_OID)
409416
}
410417
cdsSource += await dbInspect.formatCDS(db, object, fields, null, "view", schema, null, parameters)
411418

@@ -561,6 +568,7 @@ export async function convert(wss) {
561568
dbInspect.options.useExists = prompts.useExists
562569
dbInspect.options.useQuoted = prompts.useQuoted
563570
dbInspect.options.log = prompts.log
571+
dbInspect.options.userCatalogPure = prompts.useCatalogPure
564572

565573

566574
let logOutput = []
@@ -609,7 +617,7 @@ export async function convert(wss) {
609617
prompts, viewResults, wss, db, schema, cdsSource, logOutput
610618
)
611619
await writeCDS(prompts, wss, cdsSource, logOutput)
612-
await writeSynonyms(prompts, wss)
620+
await writeSynonyms(prompts, wss)
613621
break
614622
}
615623
}

0 commit comments

Comments
 (0)