drizzle-team / drizzle-team/drizzle-orm

[BUG]: Incompatible `where` in db.$count and queries

Open
#5,218 8 comments 5 reactions 0 assignees View on GitHub
1.0.0-beta.* enhancement improvement rqb
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

1.0.0-beta.8-734e789

### What version of `drizzle-kit` are you using?

1.0.0-beta.8-734e789

### Other packages

_No response_

### Describe the Bug

With Relational Queries V1 I could easily share a common `where` between queries and `db.$count`, for example for the sake of pagination:

```ts
const where = and(…);
const limit = 5;
const offset = 0;

const [users, count] = await Promise.all([
db._query.users.findMany({ where, limit, offset }),
db.$count(where),
]);

return { users, count };
```

Unfortunately with Relational Queries V2 that's no longer the case:

```ts
const where = { AND: [ … ] };
const limit = 5;
const offset = 0;

const [users, count] = await Promise.all([
db.query.users.findMany({ where, limit, offset }),
db.$count(where), // ERROR
]);

return { users, count };
```

The following error is shown in TypeScript:
```
Argument of type '{ AND: [ … ] }' is not assignable to parameter of type 'SQL'.
Type '{ AND: [ … ] }' is missing the following properties from type 'SQL': queryChunks, _, shouldInlineParams, append, and 8 more.ts(2345)
```

And in runtime:

```
error: invalid input syntax for type boolean: "{"AND":[ … ]}"
```

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.