drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Add support for prepared statements to the newly added `$count` API

Open
#3,084 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

Based on the below `$count` API first added with version [0.34.0](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.34.0).
```typescript
// how many users with the name "Dan" are in the database
const count: number = await db.$count(users, eq(name, "Dan"));
```
I expected to be able to swap my current implementation of a prepared `count` statement from
```typescript
const statement = db.select({ count: sql`count(*)` }).from(users)
.where(eq(users.name, "Dan"))).prepare('UserService.GetAmountOfDans');
```
to
```typescript
const statement = db.$count(users, eq(users.name, "Dan")).prepare('UserService.GetAmountOfDans');
```
or with a placeholder
```typescript
const statement = db.$count(users, eq(users.name, sql.placeholder('name'))).prepare('UserService.GetAmountOfName');
```
However, doing either of these two results in the following error on the `prepare` method:
`Property 'prepare' does not exist on type 'PgCountBuilder>'.`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.