Skip to content

Commit

Permalink
fix(deep-queries): properly return insert result (#803)
Browse files Browse the repository at this point in the history
For `INSERT`s, `beforeData` is always `[]` and

```js
return beforeData.length ?? rootResult
```

would always return `0`.
  • Loading branch information
David-Kunz authored Sep 10, 2024
1 parent 954edfd commit 8d800e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion db-service/lib/deep-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function onDeep(req, next) {
...Array.from(queries.inserts.values()).map(query => this.onINSERT({ query })),
])

return beforeData.length ?? rootResult
return rootResult ?? beforeData.length
}

const hasDeep = (q, target) => {
Expand Down
3 changes: 2 additions & 1 deletion db-service/test/deep/deep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ describe('test deep query generation', () => {

const insert = INSERT.into(entity).entries(entry)

await cds.db.run(insert)
const result = await cds.db.run(insert)
expect(result > 0).toBe(true)

const root = { uniqueName: entry.uniqueName, realm: entry.realm }

Expand Down

0 comments on commit 8d800e2

Please sign in to comment.