Relational query `extras` are not properly adding sql

When I try to use the drizzle orm relational query like it is show in the docs I run into an error. Rather than taking the sql that I say and then adding as to alias the value it just requests the alias.
const data = await db.query.user.findMany({
columns: {
id: true
},
extras(user, { sql }) {
return {
loweredName: sql`lower(${user.firstName})`.as(
"lowered_name"
)
};
}
});
const data = await db.query.user.findMany({
columns: {
id: true
},
extras(user, { sql }) {
return {
loweredName: sql`lower(${user.firstName})`.as(
"lowered_name"
)
};
}
});
or
const data = await db.query.user.findMany({
columns: {
id: true
},
extras: {
loweredName: sql`lower(${user.firstName})`.as("lowered_name")
}
});
const data = await db.query.user.findMany({
columns: {
id: true
},
extras: {
loweredName: sql`lower(${user.firstName})`.as("lowered_name")
}
});
Both of these make the following request:
select "id", "lowered_name" from "user"
select "id", "lowered_name" from "user"
Rather than the expected:
select lower("user"."firstName") as "lowered_name" from "user"
select lower("user"."firstName") as "lowered_name" from "user"
Also as a side note I am unable to use a string to function record for the extras like in the example.
await db.query.users.findMany({
extras: {
loweredName: (users, { sql }) => sql`lower(${users.name})`.as('lowered_name'),
},
})
await db.query.users.findMany({
extras: {
loweredName: (users, { sql }) => sql`lower(${users.name})`.as('lowered_name'),
},
})
^This throws an error. It says it expects a type of Alias<unkown>^
1 Reply
Arthur
Arthur17mo ago
Tested on drizzle-orm 0.26.0 and it works. I think this is related to this issue: https://github.com/drizzle-team/drizzle-orm/issues/763
GitHub
[BUG]: Error with aliases on select · Issue #763 · drizzle-team/dr...
What version of drizzle-orm are you using? 0.26.5 What version of drizzle-kit are you using? 0.18.1 Describe the Bug There are 2 problems, 1 with relationalQuerys and another with "normal"...
Want results from more Discord servers?
Add your server