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

Commit

Permalink
feat: support virtual fields (fixes #204) (#211)
Browse files Browse the repository at this point in the history
* feat: support virtual fields

* chore(cds): use latest minor ^5.4

* test: include virtual field

- in non-draft entity
- wait for cds^5.5 for draft entity

* docs: todo for virtual fields

* chore(cds): use 5.5

* wip(draft-mode): virtual field

* chore(deps): bump

* chore(deps): sec audit fix

* fix(dialect): force "plain" on cds db

+ refactor .skip -> todo

Co-authored-by: Gregor Wolf <[email protected]>

* chore(test): add dialect plain

Co-authored-by: Gregor Wolf <[email protected]>

* refactor(test): add dialect plain + redef var

Co-authored-by: Gregor Wolf <[email protected]>

* fix: add 4th param to rawtoexpanded fn

* fix: id w/o quotes, guid instead dummy int

* test(virtual-field): add order by on virtual field

and test for response containing "virtual field = null"

* chore(prettier): move from package.json to file

* docs: add note on dialect config option

Co-authored-by: Gregor Wolf <[email protected]>
  • Loading branch information
vobu and gregorwolf committed Oct 19, 2021
1 parent 119b214 commit 9a60e57
Show file tree
Hide file tree
Showing 17 changed files with 1,813 additions and 2,748 deletions.
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: false,
printWidth: 120,
arrowParens: 'always',
trailingComma: 'none',
singleQuote: true
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Also checkout the following blog posts on how to get started using `cds-pg` in y
- [ ] arithmetic operators + functions
- [x] add draft support (see [issue #30](https://github.com/sapmentors/cds-pg/issues/30))
- [x] add advanced deployment model that supports delta handling/migrations (see [issue #27](https://github.com/sapmentors/cds-pg/issues/27))
- [x] support [`virtual` fields](https://cap.cloud.sap/docs/cds/cdl#virtual-elements) (see [issue 204](https://github.com/sapmentors/cds-pg/issues/204))
- [ ] support [`localized` entities](https://cap.cloud.sap/docs/guides/localized-data) (see [issue 196](https://github.com/sapmentors/cds-pg/issues/196))

## Usage in your CAP project
Expand All @@ -61,6 +62,7 @@ Then add this configuration to the `cds` section of your `package.json:
"kind": "postgres"
},
"postgres": {
"dialect": "plain", // <- for cds >= 5.1
"impl": "cds-pg",
"model": [
"srv"
Expand Down
5 changes: 3 additions & 2 deletions __tests__/__assets__/cap-proj/as-pg-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"cds": {
"requires": {
"db": {
"kind": "database"
"kind": "postgres"
},
"database": {
"postgres": {
"dialect": "plain",
"impl": "../../../",
"model": ["srv"]
}
Expand Down
41 changes: 23 additions & 18 deletions __tests__/__assets__/cap-proj/db/schema.cds
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace csw;

using {cuid,managed} from '@sap/cds/common';
using {
cuid,
managed
} from '@sap/cds/common';

entity Beers : cuid, managed {
name : String(100);
abv : Decimal(3, 1);
ibu : Integer;
brewery : Association to one Brewery;
name : String(100);
abv : Decimal(3, 1);
ibu : Integer;
brewery : Association to one Brewery;
virtual rating : Integer
}

entity Brewery : cuid, managed {
Expand All @@ -16,17 +20,18 @@ entity Brewery : cuid, managed {
}

entity TypeChecks : cuid {
type_Boolean : Boolean;
type_Int32 : Integer;
type_Int64 : Integer64;
type_Decimal : Decimal(2, 1);
type_Double : Double;
type_Date : Date;
type_Time : Time;
type_DateTime : DateTime;
type_Timestamp : Timestamp;
type_String : String;
type_Binary : Binary(100);
type_LargeBinary : LargeBinary;
type_LargeString : LargeString;
type_Boolean : Boolean;
type_Int32 : Integer;
type_Int64 : Integer64;
type_Decimal : Decimal(2, 1);
type_Double : Double;
type_Date : Date;
type_Time : Time;
type_DateTime : DateTime;
type_Timestamp : Timestamp;
type_String : String;
type_Binary : Binary(100);
type_LargeBinary : LargeBinary;
type_LargeString : LargeString;
virtual type_virtual : Integer;
}
1 change: 1 addition & 0 deletions __tests__/lib/pg/_runLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const path = require('path')
module.exports = async (model, credentials, app, deployDB = false) => {
const dbProperties = {
kind: 'postgres',
dialect: 'plain',
model: model,
credentials: credentials,
}
Expand Down
1 change: 1 addition & 0 deletions __tests__/lib/pg/credentials-local-w-schema.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"dialect": "plain",
"host": "localhost",
"port": "5432",
"database": "beershop",
Expand Down
1 change: 1 addition & 0 deletions __tests__/lib/pg/draft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe.each(suiteEnvironments)(
this._model = model
this._dbProperties = {
kind: 'postgres',
dialect: 'plain',
model: this._model,
credentials: credentials,
}
Expand Down
Loading

0 comments on commit 9a60e57

Please sign in to comment.