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"
            )
        };
    }
});

or
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"

Rather than the expected:
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'),
    },
})

^This throws an error. It says it expects a type of Alias<unkown>^
Was this page helpful?