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

Type Definitions for SELECT commands - is there an improvement possible? #146

Closed
AnsgarLichter opened this issue Jul 18, 2024 · 3 comments · Fixed by #201
Closed

Type Definitions for SELECT commands - is there an improvement possible? #146

AnsgarLichter opened this issue Jul 18, 2024 · 3 comments · Fixed by #201
Assignees
Labels
enhancement New feature or request

Comments

@AnsgarLichter
Copy link

I have an entity definitions like follows:

entity Travels : managed, cuid {
  displayId          : Integer                       @readonly  default 0  @assert.unique;
  beginDate          : Date;
  endDate            : Date;
  bookingFee         : Decimal(16, 3);
  totalPrice         : Decimal(16, 3)                @readonly;
  currencyCode       : Currency;
  description        : String(40);
  travelStatus       : Association to TravelStatuses @readonly;
  agency             : Association to TravelAgencies @assert.integrity;
  customer           : Association to Passengers     @assert.integrity;
  bookings           : Composition of many Bookings
                         on bookings.travel = $self;
  bookingSupplements : Association to many BookingSupplements
                         on bookingSupplements.travel = $self;
};

Now I am writing a SELECT command:

await SELECT
  .from(Travels)
  .columns(
      'displayId',
      'invalidColumn'
  )
  .where({
    invalidColumn: 'ABC'
  });

I do not get a type error if I use an invalid column name when supplying columns or using where.

I would expect to get a type error if I use an invalid column name to make the development easier and faster.
Is this possible?
Through the .from(Travels) the valid column names could be inferred or not? I am no TypeScript expert and just enjoy using it. As I think this would be very beneficial I just want to ask if this is possible or understand why this is not possible.

@hakimio
Copy link
Contributor

hakimio commented Jul 18, 2024

Maybe try out cds-ts-repository if you need good type auto-completion:

image

@mutschosW
Copy link

You also can use the projection syntax which is provided out of the box and provides at least the typings for the columns method,

await SELECT
  .from(Travels)
  .columns((t) => [t.displayId, t.invalidColumn]) // compiler will complain that invalidColumn is not a property of t
  )
  .where({
    invalidColumn: 'ABC'
  });

@daogrady
Copy link
Contributor

daogrady commented Aug 19, 2024

Hi everyone,

I will attempt to add this in the next release of cds-types. As CQL is quite powerful and allows for several different syntaxes to express where and having, we'll have to circle in on the a full solution over time.

Best,
Daniel

@daogrady daogrady self-assigned this Aug 19, 2024
@daogrady daogrady added the enhancement New feature or request label Aug 19, 2024
@daogrady daogrady mentioned this issue Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants