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