-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(temporal data): add time slice key to conflict clause (#249)
Co-authored-by: Bob den Os <[email protected]> Co-authored-by: Patrice Bender <[email protected]> Co-authored-by: Johannes Vogel <[email protected]>
- Loading branch information
1 parent
87208af
commit 67b8edf
Showing
6 changed files
with
95 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../sqlite/test/general/temporal.test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
using {managed} from '@sap/cds/common'; | ||
using { | ||
managed, | ||
temporal | ||
} from '@sap/cds/common'; | ||
|
||
entity db.fooTemporal : managed, temporal { | ||
key ID : Integer; | ||
} | ||
|
||
@path: '/test' | ||
service test { | ||
entity foo : managed { | ||
key ID : Integer; | ||
} | ||
entity foo : managed { | ||
key ID : Integer; | ||
} | ||
|
||
entity bar { | ||
key ID : UUID; | ||
} | ||
|
||
entity bar { | ||
key ID : UUID; | ||
} | ||
entity fooLocalized { | ||
key ID : Integer; | ||
text : localized String; | ||
} | ||
|
||
entity fooLocalized { | ||
key ID : Integer; | ||
text : localized String; | ||
} | ||
entity fooTemporal as projection on db.fooTemporal; | ||
|
||
entity Images { | ||
key ID : Integer; | ||
data : LargeBinary @Core.MediaType: 'image/jpeg'; | ||
} | ||
entity Images { | ||
key ID : Integer; | ||
data : LargeBinary @Core.MediaType: 'image/jpeg'; | ||
} | ||
|
||
entity ImagesView as projection on Images { | ||
*, | ||
data as renamedData | ||
} | ||
entity ImagesView as projection on Images { | ||
*, | ||
data as renamedData | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = srv => { | ||
const { fooTemporal } = srv.entities | ||
|
||
srv.on('CREATE', fooTemporal, async function (req) { | ||
// without the fix, this UPSERT throws | ||
await UPSERT(req.data).into(fooTemporal) | ||
return req.data | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const cds = require('../../../test/cds.js') | ||
|
||
describe('temporal', () => { | ||
const { GET, POST } = cds.test(__dirname, 'model.cds') | ||
|
||
beforeAll(async () => { | ||
const db = await cds.connect.to('db') | ||
const { fooTemporal } = db.model.entities('test') | ||
await db.create(fooTemporal).entries([ | ||
{ ID: 1, validFrom: '1990-01-01T00:00:00.000Z', validTo: '9999-12-31T23:59:59.999Z' }, | ||
{ ID: 2, validFrom: '2000-01-01T00:00:00.000Z', validTo: '9999-12-31T23:59:59.999Z' } | ||
]) | ||
}) | ||
|
||
test('READ', async () => { | ||
let validAt, res | ||
|
||
validAt = '1970-01-01T00:00:00.000Z' | ||
res = await GET(`/test/fooTemporal?sap-valid-at=${validAt}`) | ||
expect(res.data.value.length).toBe(0) | ||
|
||
validAt = '1995-01-01T00:00:00.000Z' | ||
res = await GET(`/test/fooTemporal?sap-valid-at=${validAt}`) | ||
expect(res.data.value.length).toBe(1) | ||
const it = res.data.value[0] | ||
expect(it).toMatchObject({ ID: 1 }) | ||
// managed and temporal shall not clash | ||
expect(it.createdAt).not.toEqual(it.validFrom) | ||
|
||
validAt = '2010-01-01T00:00:00.000Z' | ||
res = await GET(`/test/fooTemporal?sap-valid-at=${validAt}`) | ||
expect(res.data.value.length).toBe(2) | ||
}) | ||
|
||
test('UPSERT', async () => { | ||
const validFrom = '2000-01-01T00:00:00.000Z' | ||
const url = `/test/fooTemporal?sap-valid-from=${validFrom}` | ||
const data = { ID: 42, validFrom } | ||
const res = await POST(url, data) | ||
expect(res.data).toMatchObject({ validFrom }) | ||
}) | ||
}) |