mapWith doesn't look to work with extras columns

By chance, do anyone have clue why the mapWith is never called in this small code example :
const users = await ctx.db.query.users.findMany({
orderBy: desc(schema.users.createdAt),
extras: {
followersCount:
sql`(SELECT COUNT(*) FROM ${schema.following} WHERE ${schema.following.userId} = ${schema.users.id})`
.mapWith(Number)
.as("followersCount"),
},
});

console.log(
users?.[0]?.followersCount, // "0"
typeof users?.[0]?.followersCount, // "string"
);
const users = await ctx.db.query.users.findMany({
orderBy: desc(schema.users.createdAt),
extras: {
followersCount:
sql`(SELECT COUNT(*) FROM ${schema.following} WHERE ${schema.following.userId} = ${schema.users.id})`
.mapWith(Number)
.as("followersCount"),
},
});

console.log(
users?.[0]?.followersCount, // "0"
typeof users?.[0]?.followersCount, // "string"
);
I tried to add an extras followersCount column which should map to a Number but it's never called and the runtime result type is a string even if the Typescript type for followersCount is number.
1 Reply
rphlmr ⚡
rphlmr ⚡5mo ago
(just for other readers, discussion was here https://discord.com/channels/1043890932593987624/1263248228745478164)
Want results from more Discord servers?
Add your server