drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.52k stars 487 forks source link

[BUG]: UNION with magic SQL + AS is ignored #2381

Closed Farnsi closed 1 month ago

Farnsi commented 1 month ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

Union with an "AS" field will not return the field or the fixed value.

mySql.unionAll(
  db.select({
    name: table1.name,
    imageId: table1.imageId 
  }).from(table1),
  db.select({
    name: table2.name,
    imageId: sql.raw(`4711`).as('image_id')
  }).from(table2),
)

The generated SQL is correct:

(
  SELECT `name`, `image_id` FROM `table1`
)
UNION ALL
(
  SELECT `name`, 4711 AS `image_id` FROM `table2`
);

The result is:

[{
   "name": "a name'"
},
{
   "name": "other name'"
}]

Expected behavior

[{
  "name": "a name'",
  "imageId": 1
},
{
  "name": "other name'"
  "imageId": 4711
}]

Environment & setup

No response

Farnsi commented 1 month ago

Works, had a wrong typo.