Skip to content

Commit

Permalink
fix view resolving for stream (#96)
Browse files Browse the repository at this point in the history
* fix view resolving for stream

* Update db-service/lib/SQLService.js

Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>

* add cl

* Update to cds@7.1.0

* Bump only db-service package to 7.1.1

* Update db-service/CHANGELOG.md

* add .npmrc to .gitignore

* cleanup unused

* update package-lock.json

---------

Co-authored-by: Samuel Brucksch <samuel.brucksch@sap.com>
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
Co-authored-by: Johannes Vogel <31311694+johannes-vogel@users.noreply.github.com>
Co-authored-by: Bob den Os <108393871+BobdenOs@users.noreply.github.com>
Co-authored-by: Bob den Os <bob.den.os@sap.com>
Co-authored-by: D050513 <sebastian.van.syckel@sap.com>
  • Loading branch information
7 people authored Aug 1, 2023
1 parent e5a525e commit 2f33099
Show file tree
Hide file tree
Showing 8 changed files with 1,069 additions and 820 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ dist

# Mac
.DS_Store

# NPM
.npmrc
3 changes: 2 additions & 1 deletion db-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `UPDATE` is only noop if it does not include an element annotated with `@cds.on.update`.
- `SELECT` with `'*'` that is not expanded creates now a clearer error when the column name is required.
- `SELECT` with plain SQL statements will return correct result regardless of casing.
- View resolving for streams.

## Version 1.0.1 - 2023-07-03

Expand All @@ -23,4 +24,4 @@

## Version 1.0.0 - 2023-06-23

- Initial Release
- Initial Release
2 changes: 1 addition & 1 deletion db-service/lib/SQLService.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class SQLService extends DatabaseService {
if (cqn.SELECT && cqn.elements) cqn.SELECT.expand = cqn.SELECT.expand ?? 'root'

const cmd = cqn.cmd || Object.keys(cqn)[0]
if (cmd in { INSERT: 1, DELETE: 1, UPSERT: 1, UPDATE: 1 }) {
if (cmd in { INSERT: 1, DELETE: 1, UPSERT: 1, UPDATE: 1 } || cqn.STREAM?.into) {
let resolvedCqn = resolveView(cqn, this.model, this)
if (resolvedCqn && resolvedCqn[cmd]._transitions?.[0].target) {
resolvedCqn = resolvedCqn || cqn
Expand Down
2 changes: 1 addition & 1 deletion db-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"lint": "npx eslint . && npx prettier --check . "
},
"peerDependencies": {
"@sap/cds": ">=7"
"@sap/cds": ">=7.1.1"
},
"license": "SEE LICENSE",
"devDependencies": {
Expand Down
1,844 changes: 1,036 additions & 808 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions sqlite/test/general/model.cds
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ service test {
key ID : Integer;
data : LargeBinary @Core.MediaType: 'image/jpeg';
}

entity ImagesView as projection on Images {
*,
data as renamedData
}
}
28 changes: 20 additions & 8 deletions sqlite/test/general/stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const { Readable } = require('stream')

cds.test(__dirname, 'model.cds')

const readStream = (id, done) => {
const { Images } = cds.entities('test')
const readStream = (id, entity, done) => {
const file = path.join(__dirname, 'samples/out.jpg')
STREAM.from(Images, { ID: id })
STREAM.from(entity, { ID: id })
.column('data')
.then(stream =>
stream.pipe(
Expand Down Expand Up @@ -304,7 +303,7 @@ describe('new STREAM API', () => {
.where({ ID: 1 })
.then(async rowNum => {
expect(rowNum).toEqual(1)
readStream(1, done)
readStream(1, Images, done)
})
})

Expand All @@ -317,7 +316,7 @@ describe('new STREAM API', () => {
.data(stream)
.then(async rowNum => {
expect(rowNum).toEqual(1)
readStream(1, done)
readStream(1, Images, done)
})
})

Expand All @@ -330,7 +329,20 @@ describe('new STREAM API', () => {
.data(stream)
.then(async rowNum => {
expect(rowNum).toEqual(1)
readStream(1, done)
readStream(1, Images, done)
})
})

test('WRITE stream property on view', done => {
const { ImagesView } = cds.entities('test')
const stream = fs.createReadStream(path.join(__dirname, 'samples/test.jpg'))

STREAM.into(ImagesView, 1)
.column('renamedData')
.data(stream)
.then(async rowNum => {
expect(rowNum).toEqual(1)
readStream(1, ImagesView, done)
})
})

Expand All @@ -342,7 +354,7 @@ describe('new STREAM API', () => {
.data(stream)
.then(async rowNum => {
expect(rowNum).toEqual(1)
readStream(1, done)
readStream(1, Images, done)
})
})

Expand All @@ -354,7 +366,7 @@ describe('new STREAM API', () => {
.into(Images, 1, 'data')
.then(async rowNum => {
expect(rowNum).toEqual(1)
readStream(1, done)
readStream(1, Images, done)
})
})
})
2 changes: 1 addition & 1 deletion test/scenarios/bookshop/read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const admin = {
}

describe('Bookshop - Read', () => {
const { expect, GET, POST, PUT, DELETE } = cds.test(bookshop)
const { expect, GET, POST, DELETE } = cds.test(bookshop)

test('Books', async () => {
const res = await GET('/browse/Books', { headers: { 'accept-language': 'de' } })
Expand Down

0 comments on commit 2f33099

Please sign in to comment.