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: add types for cds.ql.SELECT.hints() #408

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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