Skip to content
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

Add example for selecting from view with parameters #839

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stewsk
Copy link
Contributor

@stewsk stewsk commented Apr 16, 2024

No description provided.

cds/cdl.md Show resolved Hide resolved
@stewsk
Copy link
Contributor Author

stewsk commented Apr 16, 2024

@renejeglinsky : this is the example on using a view with parameters that we talked about yesterday.
I added a TODO where we could link to respective sections of the runtime docu where they show how to do a select on a view with parameters in the runtimes - although I don't know whether such examples do exist

@agoerler @johannes-vogel : do you have docu/examples showing how to select from a view w/ params in the runtimes that we could link here? This was explicitly asked for in a cap issue.

@johannes-vogel
Copy link
Contributor

@renejeglinsky : this is the example on using a view with parameters that we talked about yesterday. I added a TODO where we could link to respective sections of the runtime docu where they show how to do a select on a view with parameters in the runtimes - although I don't know whether such examples do exist

@agoerler @johannes-vogel : do you have docu/examples showing how to select from a view w/ params in the runtimes that we could link here? This was explicitly asked for in a cap issue.

We do not have a sample as we do not have a proper API for that. As of now, it's basically a CQN snippet you need to provide SELECT.from({ id: 'ViewWithParams', args: { p1: {val: 1}, p2: {val:2} }).

entity UsingView ( bar: Boolean )
as SELECT * from SomeView(foo: 17, bar: :bar);
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johannes-vogel Could you translate your example on this example? Does it make a difference if it's a view with param or a view selecting from a view with params?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this example you added in a comment:
SELECT.from({ id: 'ViewWithParams', args: { p1: {val: 1}, p2: {val:2} })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For Node.js, there's no programmatic API yet. You need to provide a [CQN snippet](/cds/cqn#select).
For Java, you [build a select statement and execute it with the corresponding named parameters](/java/working-with-cql/query-execution#querying-views).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johannes-vogel @MattSchur @agoerler Is the previous suggestion fine for you?

as SELECT * from SomeView(foo: 17, bar: :bar);
```

**TODO** add links to how to write queries on views w/ parameters in the runtimes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

Suggested change
**TODO** add links to how to write queries on views w/ parameters in the runtimes.
In CAP Java, run a select statement against the view with named [parameter values](/java/working-with-cql/query-execution#querying-views):
```Java
var params = Map.of("bar", true);
Result result = service.run(Select.from("UsingView"), params);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> #909

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johannes-vogel If you'd provide a similar specific example, I'd put both examples in a Node/Java code group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants