Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass through map type as normal ref #889

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db-service/lib/cqn4sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ function cqn4sql(originalQuery, model) {
}
})
return flatColumns
} else if (element.elements) {
} else if (element.elements && element.type !== 'cds.Map') {
const flatRefs = []
Object.values(element.elements).forEach(e => {
const alias = columnAlias ? `${columnAlias}_${e.name}` : null
Expand Down
2 changes: 2 additions & 0 deletions test/bookshop/db/data/sap.capire.bookshop-Maps.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ID;map
0;{"key": "value"}
8 changes: 7 additions & 1 deletion test/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ entity C : managed {
B : Integer;
toB : Composition of many B
on toB.ID = $self.B;
};
}

entity Maps {
key ID : Integer;
map : Map;
}

entity BooksAnnotated as projection on Books;
6 changes: 6 additions & 0 deletions test/compliance/literals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ describe('literals', () => {
throw new Error('not supported')
})
})

describe('maps', () => {
test.skip('missing', () => {
throw new Error('not supported')
})
})
})
4 changes: 4 additions & 0 deletions test/compliance/resources/db/basic/literals.cds
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ entity array {
integer : array of Integer;
}

entity map {
map : Map;
}

entity binaries {
binary : Binary;
largebinary : LargeBinary;
Expand Down
7 changes: 7 additions & 0 deletions test/scenarios/bookshop/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ describe('Bookshop - Insert', () => {
expect(written.price).to.be.eq(entry.price)
}
})

test('Map', async () => {
await INSERT.into('sap.capire.bookshop.Maps').entries({ ID: 1, map: { key: 'insertedValue' } })
const result = await SELECT.from('sap.capire.bookshop.Maps')

expect(result).to.deep.eq([{ ID: 0, map: { key: 'value' } }, { ID: 1, map: { key: 'insertedValue' } }])
})
})
5 changes: 5 additions & 0 deletions test/scenarios/bookshop/read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ describe('Bookshop - Read', () => {
for (const row of results) expect(row).to.deep.eq([{ID: 207},{ID: 252},{ID: 271}])
})

it('Map', async () => {
const result = await SELECT.from('sap.capire.bookshop.Maps')

expect(result).to.deep.eq([{ ID: 0, map: { key: 'value' } }])
})
it('select all authors which have written books that have genre.name = null', async () => {
await insertTemporaryData()

Expand Down
7 changes: 7 additions & 0 deletions test/scenarios/bookshop/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,11 @@ describe('Bookshop - Update', () => {
const afterUpdate = await cds.db.run(selectRichardsBooks)
expect(afterUpdate[0]).to.have.property('ID').that.equals(42)
})

test('Map', async () => {
await UPDATE.entity('sap.capire.bookshop.Maps').where("ID=", 0).set({ map: { key: 'updatedValue' } })
const result = await SELECT.from('sap.capire.bookshop.Maps')

expect(result).to.deep.eq([{ ID: 0, map: { key: 'updatedValue' } }])
})
})
Loading