-
Notifications
You must be signed in to change notification settings - Fork 139
@assert #2216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
@assert #2216
Conversation
agoerler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please introduce in smaller steps
- one case
- multiple cases
- error function
cosider using ? :
Please add some examples for moderately more complex expressions.
Like, e.g.
- "if an order has items the order's total amount must be larger then 0"
- "a book's author's name must not be null"
Co-authored-by: Adrian Görler <adrian.goerler@sap.com>
What exactly do you mean with We agreed with Johannes and Patrice yesterday that we will keep the expressions simple here and wait for the CXL docs. But I can check for a "moderately more complex expression". |
I think @agoerler meant that we split up this single block into 3 examples. After each example we explain the nature of the used expression. |
Yes, I have split up the examples already. But was not sure if |
patricebender
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 As Adrian stated, it would be nice to have a little more (complex) real life scenarios. I would have probably taken the well known Bookshop for showcasing the different scenarios. But that may be my personal taste.
You can use the ternary operator as syntactic sugar for the clumsy > cds.parse.xpr`1 > 2 ? true : false`
[
'case', 'when',
{ val: 1 }, '>',
{ val: 2 }, 'then',
{ val: true }, 'else',
{ val: false }, 'end'
] |
@patricebender - could you also omit the
|
That makes sense. When I tested it, compiler still required the default |
Co-authored-by: Patrice Bender <patrice.bender@sap.com>
I have improved the examples to use Bookshop related entities. Regarding the ternary operator, we still have to put the |
|
I would like to suggest that you introduce a few sub-sections for
|
Co-authored-by: Daniel Schlachter <schlachter.daniel@gmail.com>
Co-authored-by: Adrian Görler <adrian.goerler@sap.com>
|
After incorporating the feedback, I´m asking for another (hopefully final) round of review to the changes approved. |
agoerler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mention that @assert should be used on service level.
guides/providing-services.md
Outdated
| entity Authors : cuid, managed { | ||
| @assert: (case | ||
| when dateOfBirth > dateOfDeath then error('error.author.date', (dateOfBirth, dateOfDeath), (dateOfBirth, dateOfDeath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error function will not be release 2025/12
Describes the basic feature set of the new
@assertannotation. The full blown CXN documentation is pending and will be provided by Patrice later. Once available, we will link it here. That´s why the expressions in the examples are kept simple by intention.