Skip to content

Allow specifying type of object pick fiels #630

@danielytics

Description

@danielytics

Is your feature request related to a problem? Please describe.

I have a query like this:

/*
  @name UpdateFoo
  @param foos -> ((id, val)...)
*/
update foo f
  set val = item.val
from (values :foos!) as item(id, val)
where f.id = item.id;
foo.run({foos: [{id: 1, val: 100}, {id: 2, val: 200}]}, db)

but this doesn't work because foos is inferred as:

export interface IUpdateFooParams {
  foos: readonly ({
    id: string,
    val: string,
  })[];
}

And coercing the types in the set or where doesn't affect inference.

Describe the solution you'd like

Something similar to:

/*
  @name UpdateFoo
  @param foos -> ((id :: integer, val :: integer)...)
*/
update foo f
  set val = item.val
from (values :foos!) as item(id, val)
where f.id = item.id;

(or just set typescript types directly: @param foos -> ((id :: number, val :: number)...))

Additional context

Related, but not identical, to #395

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions