Skip to content

Commit

Permalink
feat: add types for cds.ql.SELECT.hints() (#408)
Browse files Browse the repository at this point in the history
* Add types and tests for `ql.SELECT.hints()`

* Remove unused generic type

* Add changelog entry
  • Loading branch information
schwma authored Feb 13, 2025
1 parent 3c26206 commit e5a7853
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]
### Added
- Added types for `SELECT.hints()` of `cds.ql` API

### Changed
- `CHANGELOG.md` and `LICENSE` files are no longer part of the npm package.

Expand Down
5 changes: 5 additions & 0 deletions apis/internal/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ export interface Limit {
& ((rows: number, offset?: number) => this)
}

export interface Hints {
hints: ((...hints: string[]) => this)
& ((hints: string[]) => this)
}

export interface And {
and: TaggedTemplateQueryPart<this>
& ((predicate: object) => this)
Expand Down
3 changes: 2 additions & 1 deletion apis/ql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Columns,
EntityDescription,
Having,
Hints,
GroupBy,
Limit,
OrderBy,
Expand Down Expand Up @@ -74,7 +75,7 @@ export declare class QL<T> {

}

export interface SELECT<T> extends Where<T>, And, Having<T>, GroupBy, OrderBy<T>, Limit {
export interface SELECT<T> extends Where<T>, And, Having<T>, GroupBy, OrderBy<T>, Limit, Hints {
// overload specific to SELECT
columns: Columns<T, this>['columns'] & ((projection: Projection<T>) => this)
}
Expand Down
4 changes: 4 additions & 0 deletions test/typescript/apis/project/cds-ql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ SELECT.from(Foos, f => f.ref(r => r.x)) // ref should be callable without optio
SELECT.from(Foos).orderBy('x') // x auto completed
SELECT.from(Foos).orderBy('y') // non-columns also still possible

SELECT.from(Foos).hints('x')
SELECT.from(Foos).hints('x', 'y')
SELECT.from(Foos).hints(['x', 'y'])

SELECT.from(Foos, f => {
f.x,
// @ts-expect-error - foobar is not a valid column
Expand Down

0 comments on commit e5a7853

Please sign in to comment.