drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[FEATURE]: select() field types?

Open shinebayar-g opened this issue 1 year ago • 1 comments

Describe want to want

For the following example, is it possible to determine which fields are available to use inside select({}) function?

const upperCaseNames /* : { id: number; name: string }[] */ = await db
  .select({
    id: users.id, // <-- ?
    name: sql<string>`upper(${users.fullName})`,
  })
  .from(users);

If not, is it on the roadmap or is it by design as it is?

shinebayar-g avatar Apr 29 '23 08:04 shinebayar-g

Not really, because the .select() shape can be a lot more complex than just the table fields - it can have nested objects, keys with any names, SQL expressions, fields from multiple tables with joins etc. We are currently working on a separate API for conventional querying, and it will work exactly like this, with autocomplete for all the columns - #504

dankochetov avatar Apr 29 '23 10:04 dankochetov

Hi, any info on this API? The issue tracking this seems to be marked as done, but I can't find it anywhere.

brunolau avatar Jul 10 '23 05:07 brunolau

Hi, any info on this API? The issue tracking this seems to be marked as done, but I can't find it anywhere.

It's the relational query API

relsunkaev avatar Jul 30 '23 21:07 relsunkaev

Can this issue be closed? Relational queries are a thing now.

Angelelz avatar Aug 14 '23 19:08 Angelelz