@cap-js/postgres 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,14 +1,28 @@
1
- # Change Log
1
+ # Changelog
2
2
 
3
3
  - All notable changes to this project are documented in this file.
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
- ### Version 1.3.1 - 2023-10-10
7
+ ## [1.4.0](https://github.com/cap-js/cds-dbs/compare/postgres-v1.3.1...postgres-v1.4.0) (2023-11-20)
8
+
9
+
10
+ ### Added
11
+
12
+ * adapt build plugin implementation to new API ([#319](https://github.com/cap-js/cds-dbs/issues/319)) ([aec9966](https://github.com/cap-js/cds-dbs/commit/aec9966e54cd9900f85fe7406cbe38ec5c6fa4b9))
13
+
14
+
15
+ ### Fixed
16
+
17
+ * align time function behavior ([#322](https://github.com/cap-js/cds-dbs/issues/322)) ([c3ab40a](https://github.com/cap-js/cds-dbs/commit/c3ab40a007c105465349dd2f612178367b8e713a))
18
+
19
+ ## [1.3.1](https://github.com/cap-js/cds-dbs/compare/v1.3.0...v1.3.1) (2023-10-10)
20
+
21
+ ### Fixed
8
22
 
9
23
  - `cds build`-relevant files are now correctly packaged into the release. #266
10
24
 
11
- ### Version 1.3.0 - 2023-10-06
25
+ ## Version 1.3.0 - 2023-10-06
12
26
 
13
27
  ### Added
14
28
 
package/README.md CHANGED
@@ -6,14 +6,12 @@ Welcome to the new Postgres database service for [SAP Cloud Application Programm
6
6
 
7
7
  In general, all you need to do is to install one of the database packages, as follows:
8
8
 
9
-
10
9
  ```sh
11
10
  npm add @cap-js/postgres
12
11
  ```
13
12
 
14
13
  Learn more about setup and usage in the [respective database guide](https://cap.cloud.sap/docs/guides/databases-postgres).
15
14
 
16
-
17
15
  ## Support
18
16
 
19
17
  This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/cds-dbs/issues).
@@ -22,6 +20,11 @@ This project is open to feature requests/suggestions, bug reports etc. via [GitH
22
20
 
23
21
  Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
24
22
 
23
+ ## Versioning
24
+
25
+ This library follows [Semantic Versioning](https://semver.org/).
26
+ All notable changes are documented in [CHANGELOG.md](CHANGELOG.md).
27
+
25
28
  ## Code of Conduct
26
29
 
27
30
  We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
package/cds-plugin.js CHANGED
@@ -1,9 +1,11 @@
1
- const cds = require('@sap/cds/lib')
1
+ const cds = require('@sap/cds')
2
2
 
3
3
  if (!cds.env.fiori.lean_draft) {
4
4
  throw new Error('"@cap-js/postgres" only works if cds.fiori.lean_draft is enabled. Please adapt your configuration.')
5
5
  }
6
6
 
7
- if (cds.cli.command === 'build') {
8
- module.exports = require('./lib/build')
9
- }
7
+ // requires @sap/cds-dk version >= 7.3.2
8
+ cds.build?.register?.('postgres', {
9
+ impl: '@cap-js/postgres/lib/build.js',
10
+ taskDefaults: { src: cds.env.folders.db }
11
+ })
package/lib/build.js CHANGED
@@ -1,44 +1,22 @@
1
1
  const cds = require('@sap/cds')
2
+ const { fs, path } = cds.utils
2
3
 
3
- let BuildPlugin
4
- try {
5
- ({ BuildPlugin } = require('@sap/cds-dk/lib/build'))
6
- } catch (e) {
7
- if (e.code === 'ENOTFOUND') throw `No build plugin mechanism for @sap/cds-dk found. Please install @sap/cds-dk for development using 'npm i -D @sap/cds-dk@^7.3.0'`
8
- else throw e
9
- }
10
-
11
- const { fs, path, rimraf } = cds.utils
4
+ module.exports = class PostgresBuildPlugin extends cds.build.BuildPlugin {
12
5
 
13
- module.exports = class PostgresBuildPlugin extends BuildPlugin {
14
- static hasTask() { // REVISIT: should be unnecessary -> plugin mechanism knows what to pull
15
- return cds.requires.db.kind === 'postgres'
16
- }
17
-
18
- static getTaskDefaults() {
19
- return { src: cds.env.folders.db }
20
- }
21
-
22
- init() {
23
- this.task.dest = cds.env.build.target === '.' ? path.join('gen','pg') : path.join('gen', 'pg')
24
- }
25
-
26
- async clean() {
27
- await rimraf(this.task.dest)
6
+ static hasTask() {
7
+ return cds.requires.db?.kind === 'postgres'
28
8
  }
29
9
 
30
10
  async build() {
31
11
  const model = await this.model()
32
- if (!model) {
33
- return
34
- }
12
+ if (!model) return
35
13
 
36
14
  const promises = []
37
15
  promises.push(this.write({
38
16
  dependencies: { '@sap/cds': '^7', '@cap-js/postgres': '^1' },
39
17
  scripts: { start: 'cds-deploy' },
40
- }).to('package.json'))
41
- promises.push(this.write(cds.compile.to.json(model)).to(path.join('db', 'csn.json')))
18
+ }).to('pg/package.json'))
19
+ promises.push(this.write(cds.compile.to.json(model)).to(path.join('pg/db', 'csn.json')))
42
20
 
43
21
  let data
44
22
  if (fs.existsSync(path.join(this.task.src, 'data'))) {
@@ -47,7 +25,7 @@ module.exports = class PostgresBuildPlugin extends BuildPlugin {
47
25
  data = 'csv'
48
26
  }
49
27
  if (data) {
50
- promises.push(this.copy(data).to(path.join('db', 'data')))
28
+ promises.push(this.copy(data).to(path.join('pg/db', 'data')))
51
29
  }
52
30
  return Promise.all(promises)
53
31
  }
package/lib/func.js CHANGED
@@ -13,14 +13,18 @@ const StandardFunctions = {
13
13
  endswith: (x, y) => `substr(${x},length(${x}) + 1 - length(${y})) = ${y}`,
14
14
 
15
15
  // Date and Time Functions
16
- year: x => `date_part('year',(${x})::TIMESTAMP)`,
17
- month: x => `date_part('month',(${x})::TIMESTAMP)`,
18
- day: x => `date_part('day',(${x})::TIMESTAMP)`,
19
- hour: x => `date_part('hour',(${x})::TIMESTAMP)`,
20
- minute: x => `date_part('minute',(${x})::TIMESTAMP)`,
21
- second: x => `date_part('second',(${x})::TIMESTAMP)`,
16
+ year: x => `date_part('year', ${castVal(x)})`,
17
+ month: x => `date_part('month', ${castVal(x)})`,
18
+ day: x => `date_part('day', ${castVal(x)})`,
19
+ hour: x => `date_part('hour', ${castVal(x)})`,
20
+ minute: x => `date_part('minute', ${castVal(x)})`,
21
+ second: x => `date_part('second', ${castVal(x)})`,
22
22
  }
23
23
 
24
+ const isTime = /^\d{1,2}:\d{1,2}:\d{1,2}$/
25
+ const isVal = x => x && 'val' in x
26
+ const castVal = (x) => `${x}${isVal(x) ? isTime.test(x.val) ? '::TIME' : '::TIMESTAMP' : ''}`
27
+
24
28
  const HANAFunctions = {
25
29
  // https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/f12b86a6284c4aeeb449e57eb5dd3ebd.html
26
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/postgres",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "CDS database service for Postgres",
5
5
  "homepage": "https://github.com/cap-js/cds-dbs/tree/main/postgres#cds-database-service-for-postgres",
6
6
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "@sap/cds-dk": ">=7"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
- "cds-dk": {
42
+ "@sap/cds-dk": {
43
43
  "optional": true
44
44
  }
45
45
  },