If you need to find the number of players in your database, using the count function is a simple and efficient solution. Here's how you can implement it:
With Drizzle Query:
import { count } from 'drizzle-orm';
await db
.select({ count: count() })
.from(playerTable)
In SQL:
select count(*) from playerTable;
If you want to count only the players who have Posts associated with them, you may need to perform a join operation. I usually use the "with" operator for this purpose to fetch associated data instead of just counting records.
Instead of calculating the length and then using FindMany, it makes more sense to utilize the count function. Let Drizzle and your database handle the counting process for you, rather than performing it manually in Typescript.
For more information, you can refer to the documentation: