$count #3119
Replies: 4 comments 6 replies
-
@AlexBlokh This doesn't appear to work with planetscale driver even though the types say they do. Getting |
Beta Was this translation helpful? Give feedback.
-
I love the addition. It's indeed a bit too verbose without this. @AlexBlokh have you considered adding this into the query builder API? |
Beta Was this translation helpful? Give feedback.
-
I'm getting a typescript type error.
|
Beta Was this translation helpful? Give feedback.
-
Will the support of this be added to a export let usersCountView = github.materializedView("users_count")
.as(qb =>
qb.$count().from(usersTable) // Property $count does not exist on type QueryBuilder
) |
Beta Was this translation helpful? Give feedback.
-
In recent release we've introduced
$count
API and I wanted to shine some light on why we decided to implement one.We pursue SQL-likeness with Drizzle, yet sometimes pure SQL is just bad, this is how you'd do
count
with our query builder:not that bad you might say, yet
count
type would be unknown, since we didn't explicitly tell oursql
tag the type of a column, which would beThat still wouldn't work, because PostgreSQL will return count as
bigint
and MySQL will return count asdecimal
which will be returned asstring
, so if we want something robust - we should do:These all the above are reasons why we sometimes introduce utilities like
$count
, we will be prefixing util function like this one with$
to separate them from query builder APIswe've designed it to be used as a subquery too:
this way you can easily filter out only users with at least one post
and you can use it with our relational queries too:
Beta Was this translation helpful? Give feedback.
All reactions