Compare commits

...

7 Commits

Author SHA1 Message Date
Dr. David A. Kunz
5fc3462b24 still to do: orders 2025-04-28 17:18:55 +02:00
Daniel Hutzel
efc2f3632f Moved app/routes back into srv/server, as cds build ignores the former 2025-04-28 06:55:35 +02:00
Daniel Hutzel
61ceb4a63a Removed TreeView fake handlers for SQLite 2025-04-28 06:07:40 +02:00
Daniel Hutzel
226ab2539e Using specific list of npm workspaces 2025-04-24 14:38:11 +02:00
Daniel Hutzel
56a9796329 . 2025-04-24 05:33:59 +02:00
Johannes Vogt
ece1962052 Merge pull request #834 from SAP-samples/shared-db-deps
add shared-db dependencies
2025-04-23 10:47:41 +02:00
Johannes Vogt
f90c43150a add shared-db dependencies 2025-04-23 09:42:50 +02:00
8 changed files with 28 additions and 48 deletions

View File

@@ -1,6 +0,0 @@
// Add routes to UIs from imported packages
module.exports = (app) => {
app.serve ('/bookshop') .from ('@capire/bookshop','app/vue')
app.serve ('/reviews') .from ('@capire/reviews','app/vue')
app.serve ('/orders') .from('@capire/orders','app/orders')
}

View File

@@ -1,10 +1,16 @@
const cds = require ('@sap/cds') const cds = require ('@sap/cds')
// Add routes to UIs from imported packages // Add routes to UIs from imported packages
if (!cds.env.production) cds.once ('bootstrap', require('../app/routes')) if (!cds.env.production) cds.once ('bootstrap', (app) => {
app.serve ('/bookshop') .from ('@capire/bookshop','app/vue')
app.serve ('/reviews') .from ('@capire/reviews','app/vue')
app.serve ('/orders') .from('@capire/orders','app/orders')
})
// Mashing up bookshop services with required services... // Mashing up bookshop services with required services...
cds.once ('served', async ()=>{ // called by server.js cds.once ('served', async ()=>{
const CatalogService = await cds.connect.to ('CatalogService') const CatalogService = await cds.connect.to ('CatalogService')
const ReviewsService = await cds.connect.to ('ReviewsService') const ReviewsService = await cds.connect.to ('ReviewsService')

View File

@@ -106,7 +106,7 @@
"name": "sap.fe.templates.ObjectPage", "name": "sap.fe.templates.ObjectPage",
"options": { "options": {
"settings" : { "settings" : {
"entitySet" : "Books", "contextPath" : "/Books",
"navigation" : { "navigation" : {
"Authors" : { "Authors" : {
"detail" : { "detail" : {
@@ -123,7 +123,7 @@
"name": "sap.fe.templates.ObjectPage", "name": "sap.fe.templates.ObjectPage",
"options": { "options": {
"settings" : { "settings" : {
"entitySet" : "Authors" "contextPath" : "/Authors"
} }
} }
} }

View File

@@ -99,7 +99,7 @@
"name": "sap.fe.templates.ListReport", "name": "sap.fe.templates.ListReport",
"options": { "options": {
"settings": { "settings": {
"entitySet": "Books", "contextPath": "/Books",
"initialLoad": true, "initialLoad": true,
"navigation": { "navigation": {
"Books": { "Books": {
@@ -117,7 +117,7 @@
"name": "sap.fe.templates.ObjectPage", "name": "sap.fe.templates.ObjectPage",
"options": { "options": {
"settings": { "settings": {
"entitySet": "Books" "contextPath": "/Books"
} }
} }
} }

View File

@@ -1,32 +0,0 @@
const cds = require('@sap/cds/lib')
if (cds.requires.db?.kind === 'sqlite') {
cds.on ('serving:AdminService', srv => srv.prepend(() => {
const {Genres} = srv.entities
// Register a simplistic handler for hierarchical queries
srv.on('READ', Genres, (req,next) => {
const q = req.query
// Expand query on a single row
if (q.SELECT.recurse?.where?.[0].ref[0] === 'Distance') {
q.SELECT.where[0] = 'parent_ID'
// Initial query
} else if (!q.SELECT.search && !is_count(q)) {
q.SELECT.where ??= [ 'parent_ID is null' ]
}
// Use scalar subselect for DrillState
q.SELECT.from.as = 'g'
q.SELECT.columns = q.SELECT.columns.map (c => {
if (c.ref == 'DrillState') return { xpr:[`
CASE WHEN ( SELECT count(1) from ${Genres} where parent_ID = g.ID ) > 0
THEN 'collapsed' ELSE 'leaf' END`
], as: 'DrillState' }
else return c
})
// Suppress error message: Feature "recurse" queries not supported.
delete q.SELECT.__proto__.recurse
delete q.SELECT.recurse
return next()
})
}))
}
const is_count = q => q.SELECT.columns?.length === 1 && q.SELECT.columns[0].func === 'count'

View File

@@ -5,8 +5,15 @@
"repository": "https://github.com/sap-samples/cloud-cap-samples.git", "repository": "https://github.com/sap-samples/cloud-cap-samples.git",
"author": "daniel.hutzel@sap.com", "author": "daniel.hutzel@sap.com",
"workspaces": [ "workspaces": [
"./*", "bookshop",
"./etc/*" "bookstore",
"common",
"fiori",
"orders",
"reviews",
"shared-db",
"etc/data-viewer",
"etc/loggers"
], ],
"devDependencies": { "devDependencies": {
"@cap-js/cds-test": "^0" "@cap-js/cds-test": "^0"

View File

@@ -3,7 +3,7 @@ module.exports = cds.service.impl (function(){
// Get the CSN definition for Reviews from the db schema for sub-sequent queries // Get the CSN definition for Reviews from the db schema for sub-sequent queries
// ( Note: we explicitly specify the namespace to support embedded reuse ) // ( Note: we explicitly specify the namespace to support embedded reuse )
const { Reviews, Likes } = this.entities ('sap.capire.reviews') const { Reviews, Likes } = this.entities
this.before (['CREATE','UPDATE'], 'Reviews', req => { this.before (['CREATE','UPDATE'], 'Reviews', req => {
if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1 if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1

View File

@@ -2,6 +2,11 @@
"name": "@capire/shared-db", "name": "@capire/shared-db",
"version": "3.0.0", "version": "3.0.0",
"description": "CAP Sample CDS model deployment for shared-db scenario", "description": "CAP Sample CDS model deployment for shared-db scenario",
"dependencies": {
"@capire/bookstore": "*",
"@capire/orders": "*",
"@capire/reviews": "*"
},
"cds": { "cds": {
"sql": { "sql": {
"native_hana_associations": false "native_hana_associations": false