$count #3119
AlexBlokh
started this conversation in
Show and tell
$count
#3119
Replies: 3 comments 5 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.
3 replies
-
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.
1 reply
-
I'm getting a typescript type error.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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