$with using sql operator doesn't return type?

const companiesWithPrimaryAddress = db
.$with("companiesWithPrimaryAddress")
.as(
db
.select({
name: company.name,
phone: company.phone,
email: company.email,
notes: company.notes,
isTaxExempt: company.isTaxExempt,
addressType: address.addressType,
primaryAddress: sql<string>`CONCAT(address_one, ' ', address_two, ' ', city, ' ', state, ' ', zip, ' ', country)`,
})
.from(company)
.leftJoin(address, eq(company.name, address.entityId))
.where(eq(address.addressType, "primary")),
);
const companiesWithPrimaryAddress = db
.$with("companiesWithPrimaryAddress")
.as(
db
.select({
name: company.name,
phone: company.phone,
email: company.email,
notes: company.notes,
isTaxExempt: company.isTaxExempt,
addressType: address.addressType,
primaryAddress: sql<string>`CONCAT(address_one, ' ', address_two, ' ', city, ' ', state, ' ', zip, ' ', country)`,
})
.from(company)
.leftJoin(address, eq(company.name, address.entityId))
.where(eq(address.addressType, "primary")),
);
Whenever I make a call to this table using db.with(companiesWithPrimaryAddress) the type of primaryAddress is returned as 'never'? Anyone know why?
4 Replies
Angelelz
Angelelz13mo ago
What's your dialect?
Angelelz
Angelelz13mo ago
GitHub
drizzle-orm/integration-tests/tests/pg.test.ts at 0a4e3b265ce121675...
Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅 - drizzle-team/drizzle-orm
Angelelz
Angelelz13mo ago
I see the same test in sql and mysql
DYELbrah
DYELbrahOP13mo ago
I figured it out, I was missing the .as('primary_address') after the sql`` operator use Thank you!
Want results from more Discord servers?
Add your server