Skip to content

Commit

Permalink
add cds repl and minor edits (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
renejeglinsky authored Jan 21, 2025
1 parent 356a27a commit fc77498
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 76 deletions.
17 changes: 10 additions & 7 deletions cds/cxn.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,18 @@ _operator = string
Examples:

```js
cds.parse.expr(`x<9`) ==//> returns:
[dev] cds repl
> cds.parse.expr(`x<9`) ==
{xpr:[ {ref:['x']}, '<', {val:9} ]}

cds.parse.expr(`x<9 and (y=1 or z=2)`) ==//> returns:
> cds.parse.expr(`x<9 and (y=1 or z=2)`) ==
{xpr:[
{ref:['x']}, '<', {val:9}, 'and', {xpr:[
{ref:['y']}, '=', {val:1}, 'or', {ref:['z']}, '=', {val:2}
]}
]}

cds.parse.expr(`exists books[year = 2000]`) ==//> returns:
> cds.parse.expr(`exists books[year = 2000]`) ==
{xpr:[
'exists',
{ref: [ {id:'books', where:[ {'ref':['year']}, '=', {'val': 2000} ]}]}
Expand All @@ -160,7 +161,8 @@ As an exception to that rule, CDS supports the ternary conditional operator on s
but immediately converts it to the corresponding CASE expression in CXN:

```js
cds.parse.expr(`x<10 ? y : z`) ==//> returns:
[dev] cds repl
> cds.parse.expr(`x<10 ? y : z`) ==
{xpr:['case', 'when', {ref:['x']}, '<', {val:10},
'then', {ref:['y']}, 'else', {ref:['z']}, 'end']}
```
Expand All @@ -177,9 +179,10 @@ param = { ref:[ '?' | number | name ], param:true }

Examples:
```js
cds.parse.expr(`x=:1`) == [{ref:['x']}, '=', {ref:[1], param:true}]
cds.parse.expr(`x=:y`) == [{ref:['x']}, '=', {ref:['y'], param:true}]
cds.parse.expr(`x=?`) == [{ref:['x']}, '=', {ref:['?'], param:true}]
[dev] cds repl
> cds.parse.expr(`x=:1`) //> [{ref:['x']}, '=', {ref:[1], param:true}]
> cds.parse.expr(`x=:y`) //> [{ref:['x']}, '=', {ref:['y'], param:true}]
> cds.parse.expr(`x=?`) //> [{ref:['x']}, '=', {ref:['?'], param:true}]
```

## Sub Queries
Expand Down
7 changes: 4 additions & 3 deletions guides/databases-sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,10 @@ entity Foo {
The behaviour has changed to:

```js
SELECT.from('Foo') //> [{ foo:1, bar:null }, ...] // [!code --]
SELECT.from('Foo') //> [{ foo:1 }, ...]
SELECT('bar').from('Foo') //> ERROR: no columns to read
[dev] cds repl
> SELECT.from('Foo') //> [{ foo:1, bar:null }, ...] // [!code --]
> SELECT.from('Foo') //> [{ foo:1 }, ...]
> SELECT('bar').from('Foo') //> ERROR: no columns to read
```

### <> Operator {.node}
Expand Down
2 changes: 1 addition & 1 deletion guides/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ So, the complete stack of overlaid models for the given example would look like
| *srv/my-service.cds* | service definition |
| *db/schema.cds* | underlying data model |

::: tip _Note_ <!-- -->
::: tip Set default language
The _default language_ is usually `en` but can be overridden by configuring <Config>cds.i18n.default_language</Config> in your project's _package.json_.
:::

Expand Down
17 changes: 10 additions & 7 deletions node.js/cds-compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,10 @@ Parses a source string in CQL expression syntax and returns it as a parsed expre

Examples:
```js
let cxn = cds.parse.expr (`foo.bar > 9`)
let cxn = cds.parse.expr `foo.bar > 9`
//> {xpr:[ {ref:['foo', 'bar']}, '>', {val:9} ] }
[dev] cds repl
> let cxn = cds.parse.expr (`foo.bar > 9`)
> let cxn = cds.parse.expr `foo.bar > 9` //> both return:
{xpr:[ {ref:['foo', 'bar']}, '>', {val:9} ] }
```


Expand All @@ -339,8 +340,9 @@ Convenience shortcut to `cds.parse.expr(x).xpr`

Example:
```js
let xpr = cds.parse.xpr (`foo.bar > 9`)
//> [ {ref:['foo', 'bar']}, '>', {val:9} ]
[dev] cds repl
> let xpr = cds.parse.xpr (`foo.bar > 9`) // [!code focus]
[ {ref:['foo', 'bar']}, '>', {val:9} ]
```


Expand All @@ -351,8 +353,9 @@ Convenience shortcut to `cds.parse.expr(x).ref`

Example:
```js
let ref = cds.parse.ref (`foo.bar`)
//>= ['foo', 'bar']
[dev] cds repl
> let ref = cds.parse.ref (`foo.bar`) // [!code focus]
['foo', 'bar']
```


Expand Down
Loading

0 comments on commit fc77498

Please sign in to comment.