Compare commits
6 Commits
trying-esm
...
performanc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a10a30936a | ||
|
|
cae6a21b89 | ||
|
|
bf0587b028 | ||
|
|
76195703f4 | ||
|
|
7af4e94b69 | ||
|
|
1b220508c1 |
1226
bookshop/package-lock.json
generated
Normal file
1226
bookshop/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@
|
|||||||
"index.js"
|
"index.js"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": ">=5.9",
|
"@sap/cds": "^6.1.1",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"passport": ">=0.4.1"
|
"passport": ">=0.4.1"
|
||||||
},
|
},
|
||||||
@@ -22,7 +22,10 @@
|
|||||||
"cds": {
|
"cds": {
|
||||||
"requires": {
|
"requires": {
|
||||||
"db": {
|
"db": {
|
||||||
"kind": "sql"
|
"kind": "sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"database": "sqlite.db"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
bookshop/sqlite.db
Normal file
BIN
bookshop/sqlite.db
Normal file
Binary file not shown.
@@ -1,24 +0,0 @@
|
|||||||
using { Currency, User, managed, cuid } from '@sap/cds/common';
|
|
||||||
namespace sap.capire.orders;
|
|
||||||
|
|
||||||
entity Orders : cuid, managed {
|
|
||||||
OrderNo : String @title:'Order Number'; //> readable key
|
|
||||||
Items : Composition of many {
|
|
||||||
key ID : UUID;
|
|
||||||
product : Association to Products;
|
|
||||||
quantity : Integer;
|
|
||||||
title : String; //> intentionally replicated as snapshot from product.title
|
|
||||||
price : Double; //> materialized calculated field
|
|
||||||
};
|
|
||||||
buyer : User;
|
|
||||||
currency : Currency;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This is a stand-in for arbitrary ordered Products */
|
|
||||||
entity Products @(cds.persistence.skip:'always') {
|
|
||||||
key ID : String;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// this is to ensure we have filled-in currencies
|
|
||||||
using from '@capire/common';
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
using { sap.capire.orders as my } from '../db/schema';
|
|
||||||
|
|
||||||
service OrdersService {
|
|
||||||
entity Orders as projection on my.Orders;
|
|
||||||
}
|
|
||||||
30
package-lock.json
generated
30
package-lock.json
generated
@@ -5235,9 +5235,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/moment": {
|
"node_modules/moment": {
|
||||||
"version": "2.29.3",
|
"version": "2.29.4",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
"integrity": "sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==",
|
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "*"
|
"node": "*"
|
||||||
}
|
}
|
||||||
@@ -5644,12 +5644,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/passport": {
|
"node_modules/passport": {
|
||||||
"version": "0.5.2",
|
"version": "0.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/passport/-/passport-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/passport/-/passport-0.6.0.tgz",
|
||||||
"integrity": "sha512-w9n/Ot5I7orGD4y+7V3EFJCQEznE5RxHamUxcqLT2QoJY0f2JdN8GyHonYFvN0Vz+L6lUJfVhrk2aZz2LbuREw==",
|
"integrity": "sha512-0fe+p3ZnrWRW74fe8+SvCyf4a3Pb2/h7gFkQ8yTJpAO50gDzlfjZUZTO1k5Eg9kUct22OxHLqDZoKUWRHOh9ug==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"passport-strategy": "1.x.x",
|
"passport-strategy": "1.x.x",
|
||||||
"pause": "0.0.1"
|
"pause": "0.0.1",
|
||||||
|
"utils-merge": "^1.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4.0"
|
"node": ">= 0.4.0"
|
||||||
@@ -11283,9 +11284,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.29.3",
|
"version": "2.29.4",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.3.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
"integrity": "sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw=="
|
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
|
||||||
},
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
@@ -11593,12 +11594,13 @@
|
|||||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
|
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
|
||||||
},
|
},
|
||||||
"passport": {
|
"passport": {
|
||||||
"version": "0.5.2",
|
"version": "0.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/passport/-/passport-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/passport/-/passport-0.6.0.tgz",
|
||||||
"integrity": "sha512-w9n/Ot5I7orGD4y+7V3EFJCQEznE5RxHamUxcqLT2QoJY0f2JdN8GyHonYFvN0Vz+L6lUJfVhrk2aZz2LbuREw==",
|
"integrity": "sha512-0fe+p3ZnrWRW74fe8+SvCyf4a3Pb2/h7gFkQ8yTJpAO50gDzlfjZUZTO1k5Eg9kUct22OxHLqDZoKUWRHOh9ug==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"passport-strategy": "1.x.x",
|
"passport-strategy": "1.x.x",
|
||||||
"pause": "0.0.1"
|
"pause": "0.0.1",
|
||||||
|
"utils-merge": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"passport-strategy": {
|
"passport-strategy": {
|
||||||
|
|||||||
@@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Note: this is designed for the OrdersService being co-located with
|
// Note: this is designed for the PerformanceService being co-located with
|
||||||
// bookshop. It does not work if OrdersService is run as a separate
|
// bookshop. It does not work if PerformanceService is run as a separate
|
||||||
// process, and is not intended to do so.
|
// process, and is not intended to do so.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using { OrdersService } from '../srv/orders-service';
|
using { PerformanceService } from '../srv/performance-service';
|
||||||
|
|
||||||
|
|
||||||
@odata.draft.enabled
|
@odata.draft.enabled
|
||||||
annotate OrdersService.Orders with @(
|
annotate PerformanceService.Orders with @(
|
||||||
UI: {
|
UI: {
|
||||||
SelectionFields: [ createdAt, createdBy ],
|
SelectionFields: [ createdAt, createdBy ],
|
||||||
LineItem: [
|
LineItem: [
|
||||||
@@ -68,7 +68,7 @@ annotate OrdersService.Orders with @(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
annotate OrdersService.Orders.Items with @(
|
annotate PerformanceService.Orders.Items with @(
|
||||||
UI: {
|
UI: {
|
||||||
LineItem: [
|
LineItem: [
|
||||||
{Value: product_ID, Label:'Product ID'},
|
{Value: product_ID, Label:'Product ID'},
|
||||||
5
performance/db/data/sap.capire.performance-Authors.csv
Normal file
5
performance/db/data/sap.capire.performance-Authors.csv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ID;name;dateOfBirth;placeOfBirth;dateOfDeath;placeOfDeath
|
||||||
|
101;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire
|
||||||
|
107;Charlotte Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire
|
||||||
|
150;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland
|
||||||
|
170;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England
|
||||||
|
6
performance/db/data/sap.capire.performance-Books.csv
Normal file
6
performance/db/data/sap.capire.performance-Books.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
ID;title;descr;author_ID;stock;price;currency_code
|
||||||
|
201;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";101;12;11.11;GBP
|
||||||
|
207;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;11;12.34;GBP
|
||||||
|
251;The Raven;"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;333;13.13;USD
|
||||||
|
252;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;555;14;USD
|
||||||
|
271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;150;JPY
|
||||||
|
@@ -0,0 +1,5 @@
|
|||||||
|
ID;locale;title;descr
|
||||||
|
201;de;Sturmhöhe;Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (1818–1848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts.
|
||||||
|
201;fr;Les Hauts de Hurlevent;Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme d’Ellis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal.
|
||||||
|
207;de;Jane Eyre;Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte
|
||||||
|
252;de;Eleonora;“Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit.
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
ID;up__ID;quantity;product_ID;title;price
|
ID;Header_ID;quantity;product_ID;title;price
|
||||||
58040e66-1dcd-4ffb-ab10-fdce32028b79;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;201;Wuthering Heights;11.11
|
58040e66-1dcd-4ffb-ab10-fdce32028b79;7e2f2640-6866-4dcf-8f4d-3027aa831cad;10;201;Wuthering Heights;11.11
|
||||||
64e718c9-ff99-47f1-8ca3-950c850777d4;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;271;Catweazle;15
|
64e718c9-ff99-47f1-8ca3-950c850777d4;7e2f2640-6866-4dcf-8f4d-3027aa831cad;501;271;Catweazle;15
|
||||||
e9641166-e050-4261-bfee-d1e797e6cb7f;64e718c9-ff99-47f1-8ca3-950c850777d4;2;252;Eleonora;28
|
e9641166-e050-4261-bfee-d1e797e6cb7f;64e718c9-ff99-47f1-8ca3-950c850777d4;499;252;Eleonora;28
|
||||||
|
122
performance/db/schema.cds
Normal file
122
performance/db/schema.cds
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
using { Currency, cuid, managed } from '@sap/cds/common';
|
||||||
|
|
||||||
|
namespace sap.capire.performance;
|
||||||
|
|
||||||
|
|
||||||
|
entity OrdersHeaders : managed {
|
||||||
|
key ID : UUID;
|
||||||
|
OrderNo : String @title:'Order Number'; //> readable key
|
||||||
|
buyer : String;
|
||||||
|
currency : Currency;
|
||||||
|
Items : Composition of many OrdersItems on Items.Header = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity OrdersItems {
|
||||||
|
key ID : UUID;
|
||||||
|
product : Association to Books;
|
||||||
|
quantity : Integer;
|
||||||
|
title : String; //> intentionally replicated as snapshot from product.title
|
||||||
|
price : Double; //> materialized calculated field
|
||||||
|
Header : Association to OrdersHeaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
entity Books {
|
||||||
|
key ID : Integer;
|
||||||
|
title : localized String(111);
|
||||||
|
descr : localized String(1111);
|
||||||
|
author : Association to Authors;
|
||||||
|
stock : Integer;
|
||||||
|
price : Decimal;
|
||||||
|
currency : Currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Authors {
|
||||||
|
key ID : Integer;
|
||||||
|
name : String(111);
|
||||||
|
dateOfBirth : Date;
|
||||||
|
dateOfDeath : Date;
|
||||||
|
placeOfBirth : String;
|
||||||
|
placeOfDeath : String;
|
||||||
|
books : Association to many Books on books.author = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
entity Apples : cuid, managed {
|
||||||
|
description : String;
|
||||||
|
vendor : association to one Vendor;
|
||||||
|
appleDetails : appleDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Bananas : cuid, managed {
|
||||||
|
description : String;
|
||||||
|
vendor : association to one Vendor;
|
||||||
|
bananaDetails : bananaDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Cherries : cuid, managed {
|
||||||
|
description : String;
|
||||||
|
vendor : association to one Vendor;
|
||||||
|
cherryDetails : cherryDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Mangos : cuid, managed {
|
||||||
|
description : String;
|
||||||
|
vendor : association to one Vendor;
|
||||||
|
mangoDetails : mangoDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Vendor : cuid, managed {
|
||||||
|
description : String;
|
||||||
|
}
|
||||||
|
|
||||||
|
type appleDetailsType : String;
|
||||||
|
type bananaDetailsType : String;
|
||||||
|
type cherryDetailsType : String;
|
||||||
|
type mangoDetailsType : String;
|
||||||
|
|
||||||
|
entity Fruit : cuid, managed {
|
||||||
|
type : String enum { apple; banana; cherry; mango };
|
||||||
|
description : String;
|
||||||
|
vendor : association to one Vendor;
|
||||||
|
appleDetails : composition of AppleDetails;
|
||||||
|
bananaDetails : composition of BananaDetails;
|
||||||
|
cherryDetails : composition of CherryDetails;
|
||||||
|
mangoDetails : composition of MangoDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity AppleDetails : cuid {
|
||||||
|
appleDetails : appleDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity BananaDetails : cuid {
|
||||||
|
bananaDetails : bananaDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity CherryDetails : cuid {
|
||||||
|
cherryDetails : cherryDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity MangoDetails : cuid {
|
||||||
|
mangoDetails : mangoDetailsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
view Banana as select from Fruit
|
||||||
|
{
|
||||||
|
type,
|
||||||
|
description,
|
||||||
|
vendor,
|
||||||
|
bananaDetails,
|
||||||
|
}
|
||||||
|
where type = 'banana';
|
||||||
|
|
||||||
|
|
||||||
|
aspect apple { appleDetails : appleDetailsType; };
|
||||||
|
aspect banana { bananaDetails : bananaDetailsType;};
|
||||||
|
aspect cherry { cherryDetails : cherryDetailsType;};
|
||||||
|
aspect mango { mangoDetails : mangoDetailsType; };
|
||||||
|
entity Fruit_2 : apple, banana, cherry, mango, cuid, managed {
|
||||||
|
type : String enum { apple; banana; cherry; mango };
|
||||||
|
description : String;
|
||||||
|
vendor : association to one Vendor;
|
||||||
|
}
|
||||||
95
performance/srv/performance-service.cds
Normal file
95
performance/srv/performance-service.cds
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
using { sap.capire.performance as my } from '../db/schema';
|
||||||
|
|
||||||
|
service PerformanceService {
|
||||||
|
entity OrdersHeaders as projection on my.OrdersHeaders;
|
||||||
|
entity OrdersItems as projection on my.OrdersItems;
|
||||||
|
entity Books as projection on my.Books;
|
||||||
|
entity Authors as projection on my.Authors;
|
||||||
|
|
||||||
|
// static
|
||||||
|
view OrdersItemsViewJoin as select
|
||||||
|
|
||||||
|
OrdersHeaders.ID as Header_ID,
|
||||||
|
OrdersHeaders.OrderNo as OrderNo,
|
||||||
|
OrdersHeaders.buyer as buyer,
|
||||||
|
OrdersHeaders.currency as currency,
|
||||||
|
key OrdersItems.ID as Item_ID,
|
||||||
|
OrdersItems.product as product,
|
||||||
|
OrdersItems.quantity as quantity,
|
||||||
|
OrdersItems.title as title,
|
||||||
|
OrdersItems.price as price
|
||||||
|
|
||||||
|
from OrdersHeaders JOIN OrdersItems on OrdersHeaders.ID = OrdersItems.Header.ID;
|
||||||
|
|
||||||
|
// dynamic entity
|
||||||
|
entity OrderItemsViewAssoc as projection on OrdersHeaders;
|
||||||
|
|
||||||
|
// sort on right table
|
||||||
|
view SortedOrdersJoin as select
|
||||||
|
OrdersHeaders.ID as Header_ID,
|
||||||
|
OrdersHeaders.OrderNo as OrderNo,
|
||||||
|
OrdersHeaders.buyer as buyer,
|
||||||
|
OrdersHeaders.currency as currency,
|
||||||
|
key OrdersItems.ID as Item_ID,
|
||||||
|
OrdersItems.product as product,
|
||||||
|
OrdersItems.quantity as quantity,
|
||||||
|
OrdersItems.title as title,
|
||||||
|
OrdersItems.price as price
|
||||||
|
from OrdersHeaders JOIN OrdersItems on OrdersHeaders.ID = OrdersItems.Header.ID
|
||||||
|
order by title;
|
||||||
|
|
||||||
|
// sort on items and join back to header via assoc
|
||||||
|
|
||||||
|
view SortedOrdersAssoc as select
|
||||||
|
from OrdersItems {*, Header.OrderNo, Header.buyer, Header.currency }
|
||||||
|
order by OrdersItems.title;
|
||||||
|
|
||||||
|
// filter on right table
|
||||||
|
|
||||||
|
view FilteredOrdersJoin as select
|
||||||
|
OrdersHeaders.ID as Header_ID,
|
||||||
|
OrdersHeaders.OrderNo as OrderNo,
|
||||||
|
OrdersHeaders.buyer as buyer,
|
||||||
|
OrdersHeaders.currency as currency,
|
||||||
|
key OrdersItems.ID as Item_ID,
|
||||||
|
OrdersItems.product as product,
|
||||||
|
OrdersItems.quantity as quantity,
|
||||||
|
OrdersItems.title as title,
|
||||||
|
OrdersItems.price as price
|
||||||
|
from OrdersHeaders JOIN OrdersItems on OrdersHeaders.ID = OrdersItems.Header.ID
|
||||||
|
where price > 100;
|
||||||
|
|
||||||
|
// filter on items and join back to header via assoc
|
||||||
|
|
||||||
|
view FilteredOrdersAssoc as select
|
||||||
|
from OrdersItems {*, Header.OrderNo, Header.buyer, Header.currency }
|
||||||
|
where OrdersItems.price > 100;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO avoid CASE -- Denormalization of expensive complex structures,
|
||||||
|
// calculate on write instead of read
|
||||||
|
|
||||||
|
// CASE -> try to remodel to avoid CASE, if re-modelling is not possible,
|
||||||
|
// fill redundant fields at write
|
||||||
|
|
||||||
|
entity OrdersItemsCaseView as projection on OrdersItems {
|
||||||
|
*,
|
||||||
|
case
|
||||||
|
when quantity > 500 then 'Large'
|
||||||
|
when quantity > 100 then 'Medium'
|
||||||
|
else 'Small'
|
||||||
|
end as category : String
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extend my.OrdersItems with {
|
||||||
|
itemCategory: String enum{ Small; Medium; Large;};
|
||||||
|
// fill itemCategory at runtime in performance-service.js
|
||||||
|
}
|
||||||
|
|
||||||
|
entity OrdersItemsNoCaseView as projection on OrdersItems {
|
||||||
|
*,
|
||||||
|
itemCategory as category
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,6 +5,14 @@ class OrdersService extends cds.ApplicationService {
|
|||||||
init(){
|
init(){
|
||||||
const { 'Orders.Items':OrderItems } = this.entities
|
const { 'Orders.Items':OrderItems } = this.entities
|
||||||
|
|
||||||
|
// fill itemCategory at runtime
|
||||||
|
this.before (['CREATE', 'UPDATE'], async req =>{
|
||||||
|
if(req.data.quantity > 500) {req.data.itemCategory = 'Large'}
|
||||||
|
else if (req.data.quantity > 100) {req.data.itemCategory = 'Medium'}
|
||||||
|
else {req.data.itemCategory = 'Small'}
|
||||||
|
})
|
||||||
|
//
|
||||||
|
|
||||||
this.before ('UPDATE', 'Orders', async function(req) {
|
this.before ('UPDATE', 'Orders', async function(req) {
|
||||||
const { ID, Items } = req.data
|
const { ID, Items } = req.data
|
||||||
if (Items) for (let { product_ID, quantity } of Items) {
|
if (Items) for (let { product_ID, quantity } of Items) {
|
||||||
Reference in New Issue
Block a user