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

feat: query modifiers on expand ref are propagated to subquery #1049

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

patricebender
Copy link
Member

enable the following:

cds.ql`SELECT name, books[order by price] { * } FROM Authors`

it is still possible to have query modifiers defined as sibling property to expand:

{
            ref: ['author'],
            expand: [
              {
                ref: ['name'],
              },
            ],
            limit: {
              offset: {
                val: 1,
              },
              rows: {
                val: 1,
              },
            },
            orderBy: [
              {
                ref: ['name'],
                sort: 'asc',
              },
            ],
          }

--> If both are set, the modifiers in the ref of the expanded association have precedence

enable the following:

```js
cds.ql`SELECT name, books[order by price] { * } FROM Authors`
```

it is still possible to have query modifiers defined as sibling property to `expand`:

```js
{
            ref: ['author'],
            expand: [
              {
                ref: ['name'],
              },
            ],
            limit: {
              offset: {
                val: 1,
              },
              rows: {
                val: 1,
              },
            },
            orderBy: [
              {
                ref: ['name'],
                sort: 'asc',
              },
            ],
          }
```

--> If both are set, the modifiers in the `ref` of the expanded association
have precedence
}
const queryModifiers = { ...column, ...ref.at(-1) }
for (const [key, value] of Object.entries(queryModifiers)) {
if (key in { limit: 1, orderBy: 1, groupBy: 1, excluding: 1, where: 1, having: 1 }) subqueryBase[key] = value
Copy link
Member Author

Choose a reason for hiding this comment

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

everything covered?

Copy link
Contributor

Choose a reason for hiding this comment

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

compared with cqn2sql and lgtm.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 but you can take out excluding → that is always next to expand or inline. Also in CQL syntax as supported by the compiler, and hence the CQN produced by it:

cds.ql `SELECT from Authors { ID, name, books[order by title desc limit 1] {*} excluding { descr } }`
 cds.ql {
  SELECT: {
    from: { ref: [ 'Authors' ] },
    columns: [
      { ref: [ 'ID' ] },
      { ref: [ 'name' ] },
      {
        ref: [
          {
            id: 'books',
            orderBy: [ { ref: [ 'title' ], sort: 'desc' } ],
            limit: { rows: { val: 1 } }
          }
        ],
        expand: [ '*' ],
        excluding: [ 'descr' ]
      }
    ]
  }
}

@patricebender patricebender added the next release pr to be checked for next release label Feb 27, 2025
@patricebender patricebender merged commit 39fbadf into main Feb 27, 2025
6 checks passed
@patricebender patricebender deleted the patrice/props-expand branch February 27, 2025 11:52
@cap-bots cap-bots mentioned this pull request Feb 27, 2025
patricebender added a commit that referenced this pull request Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next release pr to be checked for next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants