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

@sap/cds 6.5.0 compatibility #383

Merged
merged 16 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module.exports = {
semi: false,
printWidth: 120,
arrowParens: 'always',
trailingComma: 'none',
singleQuote: true
trailingComma: 'all',
singleQuote: true,
tabWidth: 2,
proseWrap: 'never',
}
2 changes: 1 addition & 1 deletion __tests__/lib/pg/draft.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/deploy')
const deploy = require('@sap/cds/lib/dbs/cds-deploy')

// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
Expand Down
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/deploy')
const deploy = require('@sap/cds/lib/dbs/cds-deploy')

// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/pg/service-admin.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/deploy')
const deploy = require('@sap/cds/lib/dbs/cds-deploy')

cds.env.requires.db = { kind: 'postgres' }
cds.env.requires.postgres = {
Expand Down
8 changes: 4 additions & 4 deletions __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/deploy')
const deploy = require('@sap/cds/lib/dbs/cds-deploy')

// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
Expand Down Expand Up @@ -102,13 +102,13 @@ describe.each(suiteEnvironments)(
})

test(' -> Timestamp', async () => {
const value = '2012-12-03T07:16:23.574Z';
const value = '2012-12-03T07:16:23.574Z'
const response = await request.post('/beershop/TypeChecks').send({
type_Timestamp: value,
})
expect(response.status).toStrictEqual(201)
const verify = await request.get(`/beershop/TypeChecks(${response.body.ID})`).send()
expect(verify.body.type_Timestamp).toStrictEqual(value);
expect(verify.body.type_Timestamp).toStrictEqual(value)
})

test(' -> String', async () => {
Expand Down Expand Up @@ -140,5 +140,5 @@ describe.each(suiteEnvironments)(
expect(response.status).toStrictEqual(201)
})
})
}
},
)
2 changes: 1 addition & 1 deletion __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/deploy')
const deploy = require('@sap/cds/lib/dbs/cds-deploy')
// const path = require('path')

// mock (package|.cds'rc).json entries
Expand Down
14 changes: 7 additions & 7 deletions __tests__/lib/pg/timestamp.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/deploy')
const deploy = require('@sap/cds/lib/dbs/cds-deploy')

// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
Expand Down Expand Up @@ -42,13 +42,13 @@ describe.each(suiteEnvironments)(
})

describe('Timestamp TEST', () => {

test(' -> Check modifiedAt', async () => {
//Set Different TimeZone
await cds.run(`alter user postgres set timezone = 'EST'`, [])//UTC,EST
await cds.run(`alter user postgres set timezone = 'EST'`, []) //UTC,EST
const beforeTimestamp = new Date()
beforeTimestamp.setMilliseconds(0);
await request.put('/beershop/Beers/9e1704e3-6fd0-4a5d-bfb1-13ac47f7976b')
beforeTimestamp.setMilliseconds(0)
await request
.put('/beershop/Beers/9e1704e3-6fd0-4a5d-bfb1-13ac47f7976b')
.send({
name: 'Changed name',
ibu: 10,
Expand All @@ -58,8 +58,8 @@ describe.each(suiteEnvironments)(
const response = await request.get('/beershop/Beers/9e1704e3-6fd0-4a5d-bfb1-13ac47f7976b')
const afterTimestamp = new Date()
const modifiedAt = new Date(response.body.modifiedAt)
expect((beforeTimestamp <= modifiedAt) && (modifiedAt <= afterTimestamp)).toBe(true)
expect(beforeTimestamp <= modifiedAt && modifiedAt <= afterTimestamp).toBe(true)
})
})
}
},
)
24 changes: 22 additions & 2 deletions lib/pg/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ module.exports = class PostgresDatabase extends cds.DatabaseService {
* before
*/
// ensures the correct model is present (e.g., tenant extensions)
this._ensureModel && this.before('*', this._ensureModel)
this.before('*', this._ensureModel)
// VIRTUAL, MANAGED, Keys and null checks
this.before(['CREATE', 'UPDATE'], '*', this._input)
// "flattens" the query
// and "redirects" modification statements (CUD) from view to actual table
this.before(['CREATE', 'READ', 'UPDATE', 'DELETE'], '*', rewrite)
this.before('READ', '*', this._virtual)
this.before('READ', '*', this._virtual.bind(this))

/*
* on
Expand Down Expand Up @@ -121,6 +121,18 @@ module.exports = class PostgresDatabase extends cds.DatabaseService {
})
}

/**
* Retrieve model definition from ApplicationService
*/
_ensureModel() {
for (const service of cds.services) {
if (service instanceof cds.ApplicationService) {
this.model = service.model
break
}
}
}

/**
* assign request metadata
* @param {Object} req currently served express http request, enhanced by cds
Expand Down Expand Up @@ -203,4 +215,12 @@ module.exports = class PostgresDatabase extends cds.DatabaseService {

return true
}

// Required for CDS 6.x
getDbUrl() {
const credentials = this.options.credentials || this.options || {}
let dbUrl = `postgres://${credentials.host}//${credentials.database}`

return dbUrl
}
}
Loading