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

Commit

Permalink
feat(cds): support for 4.4 (#77)
Browse files Browse the repository at this point in the history
* @sap/cds/lib/db/deploy

* @sap/cds~4.4

* package-lock.json

* test: limit fields in expand
fix issue with managed fields

* chore: dependencies, reactivate husky
  • Loading branch information
gregorwolf authored Dec 8, 2020
1 parent 679ec8f commit b23cb92
Show file tree
Hide file tree
Showing 7 changed files with 1,468 additions and 987 deletions.
2 changes: 1 addition & 1 deletion __tests__/lib/pg/ql.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cds = require('@sap/cds')
const deploy = require('@sap/cds/lib/srv/db/deploy')
const deploy = require('@sap/cds/lib/db/deploy')

// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/pg/service-types.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cds = require('@sap/cds')
const deploy = require('@sap/cds/lib/srv/db/deploy')
const deploy = require('@sap/cds/lib/db/deploy')

// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
Expand Down
8 changes: 5 additions & 3 deletions __tests__/lib/pg/service.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cds = require('@sap/cds')
const deploy = require('@sap/cds/lib/srv/db/deploy')
const deploy = require('@sap/cds/lib/db/deploy')
// const path = require('path')

// mock (package|.cds'rc).json entries
Expand Down Expand Up @@ -132,12 +132,14 @@ describe.each(suiteEnvironments)('[%s] OData to Postgres dialect', (
)
})
test('odata: $expand single entity on 1:1 rel -> sql: sub-select single record from expand-target table', async () => {
const response = await request.get('/beershop/Beers/9e1704e3-6fd0-4a5d-bfb1-13ac47f7976b?$expand=brewery')
const response = await request.get(
'/beershop/Beers/9e1704e3-6fd0-4a5d-bfb1-13ac47f7976b?$expand=brewery($select=ID,name)'
)
expect(response.status).toStrictEqual(200)
expect(response.body.brewery.ID).toStrictEqual('fa6b959e-3a01-40ef-872e-6030ee4de4e5')
})
test('odata: $expand entityset on 1:1 rel -> sql: sub-select from expand-target table', async () => {
const response = await request.get('/beershop/Beers?$expand=brewery')
const response = await request.get('/beershop/Beers?$expand=brewery($select=ID,name)')
expect(response.status).toStrictEqual(200)
expect(response.body.value).toEqual(
expect.arrayContaining([
Expand Down
2 changes: 1 addition & 1 deletion bin/cds-pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const [, , action, model, to, db] = process.argv

const deploy = async () => {
const cds = require('@sap/cds')
const cds_deploy = require('@sap/cds/lib/srv/db/deploy')
const cds_deploy = require('@sap/cds/lib/db/deploy')

await cds.connect()
await cds_deploy(model, {}).to(db)
Expand Down
37 changes: 3 additions & 34 deletions lib/pg/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ module.exports = class PostgresDatabase extends cds.DatabaseService {
/*
* before
*/
// currently needed for transaction handling
this._ensureOpen && this.before('*', this._ensureOpen)
// ensures the correct model is present (e.g., tenant extensions)
this._ensureModel && this.before('*', this._ensureModel)
// "flattens" the query
// and "redirects" modification statements (CUD) from view to actual table
Expand All @@ -105,38 +104,8 @@ module.exports = class PostgresDatabase extends cds.DatabaseService {
/*
* tx
*/
this.on('BEGIN', async function (req) {
this.dbc = await this.acquire(req)
await this.dbc.query(req.event)

// currently needed for continue with tx
this._state = req.event

return 'dummy'
})

this.on('COMMIT', async function (req) {
await this.dbc.query(req.event)

// currently needed for continue with tx
this._state = req.event

await this.release(this.dbc)

return 'dummy'
})

this.on('ROLLBACK', async function (req) {
try {
await this.dbc.query(req.event)
} finally {
await this.release(this.dbc)
}

// currently needed for continue with tx
this._state = req.event

return 'dummy'
this.on(['BEGIN', 'COMMIT', 'ROLLBACK'], function (req) {
return this.dbc.query(req.event)
})

/*
Expand Down
Loading

0 comments on commit b23cb92

Please sign in to comment.