Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Support for @odata.draft.enabled #30

Closed
gregorwolf opened this issue Sep 29, 2020 · 3 comments
Closed

Support for @odata.draft.enabled #30

gregorwolf opened this issue Sep 29, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@gregorwolf
Copy link
Contributor

gregorwolf commented Sep 29, 2020

In the branch gregorwolf:feature/draft-support I've added a new entity in the service which I've annotated with @odata.draft.enabled unfortuantely already the first simple READ / GET request to the entity fails with this error:

nsole.error
[2020-09-29T20:18:44.234Z | ERROR | 1310454]: Error stacktrace: error: syntax error at or near "." at Parser.parseErrorMessage (/home/gwolf/projects/cds-pg/node_modules/pg-protocol/src/parser.ts:357:11) at Parser.handlePacket (/home/gwolf/projects/cds-pg/node_modules/pg-protocol/src/parser.ts:186:21) at Parser.parse (/home/gwolf/projects/cds-pg/node_modules/pg-protocol/src/parser.ts:101:30) at Socket. (/home/gwolf/projects/cds-pg/node_modules/pg-protocol/src/index.ts:7:48) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

The generated SQL is:

SELECT active AS "active" .ID AS "ID" , active AS "active" .type_Boolean AS "type_Boolean" , active AS "active" .type_Int32 AS "type_Int32" , active AS "active" .type_Int64 AS "type_Int64" , active AS "active" .type_Decimal AS "type_Decimal" , active AS "active" .type_Double AS "type_Double" , active AS "active" .type_Date AS "type_Date" , active AS "active" .type_Time AS "type_Time" , active AS "active" .type_DateTime AS "type_DateTime" , active AS "active" .type_Timestamp AS "type_Timestamp" , active AS "active" .type_String AS "type_String" , active AS "active" .type_Binary AS "type_Binary" , active AS "active" .type_LargeBinary AS "type_LargeBinary" , active AS "active" .type_LargeString AS "type_LargeString" , true AS "IsActiveEntity", false AS "HasActiveEntity", null AS "DraftAdministrativeData_DraftUUID", CASE WHEN DRAFTS.DRAFTADMINISTRATIVEDATA_DRAFTUUID IS NOT NULL THEN TRUE ELSE FALSE END AS "HasDraftEntity" FROM BeershopService_TypeChecksWithDraft active LEFT JOIN BeershopService_TypeChecksWithDraft_drafts drafts ON active.ID = drafts.ID ORDER BY active.ID ASC LIMIT 1000

Looks like the "active AS " which is added to every column must be removed. Also the space betwen i.e. "active" .ID must be removed. "active".ID should work.

The generated SQL for sqlite is:

SELECT active.ID, active.type_Boolean, active.type_Int32, active.type_Int64, active.type_Decimal, active.type_Double, active.type_Date, active.type_Time, active.type_DateTime, active.type_Timestamp, active.type_String, active.type_Binary, active.type_LargeBinary, active.type_LargeString, true AS "IsActiveEntity", false AS "HasActiveEntity", null AS "DraftAdministrativeData_DraftUUID", CASE WHEN DRAFTS.DRAFTADMINISTRATIVEDATA_DRAFTUUID IS NOT NULL THEN TRUE ELSE FALSE END AS "HasDraftEntity" FROM BeershopService_TypeChecksWithDraft active LEFT JOIN BeershopService_TypeChecksWithDraft_drafts drafts ON active.ID = drafts.ID ORDER BY active.ID COLLATE NOCASE ASC LIMIT 1000

@gregorwolf gregorwolf added the enhancement New feature or request label Sep 29, 2020
@gregorwolf
Copy link
Contributor Author

When switching to the edit mode of an existing entity the lib/pg/execute.js#L84 is executed:

results = results.map((result) => remapColumnNames(model.definitions[cqn.INSERT.into], result))

The value of cqn.INSERT.into that is: 'BeershopAdminService.Breweries_drafts' is not found in the model.definitions. It returns an undefined. So maybe adding a check here can provide a first workaround.

@gregorwolf
Copy link
Contributor Author

Quite some progress with draft support today. The read doesn't cause an exit anymore. PR #50 containes the adjustments I've made so far. @mikezaschka do you see a way that we can create the fields in table BeershopService_TypeChecksWithDraft_drafts respecting CASE? See my comment here.

@gregorwolf
Copy link
Contributor Author

I've tested the create and change with draft in the pg-beershop. Seems to work so far.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant