Jigglytoine
Jigglytoine
DTDrizzle Team
Created by Jigglytoine on 7/17/2024 in #help
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.
2 replies