Skip to content

Commit 0255f95

Browse files
committed
Update CHANGELOG
1 parent 62734fa commit 0255f95

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
## Version History
1212

13+
$## v17.1.0
14+
15+
- :rocket: Add generic `.count()` function
16+
1317
### v17.0.1
1418

1519
- :arrow_up: Update Core Deps

generic.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export type GenericListInput = {
3838
where?: SQL<unknown>;
3939
}
4040

41+
export type GenericCountInput = {
42+
order?: GenericListOrder;
43+
where?: SQL<unknown>;
44+
}
45+
4146
export type GenericStreamInput = {
4247
where?: SQL<unknown>;
4348
}
@@ -136,6 +141,15 @@ export default class Drizzle<T extends GenericTable> {
136141
return generic;
137142
}
138143

144+
async count(query: GenericCountInput = {}): Promise<number> {
145+
const pgres = await this.pool.select({
146+
count: sql<number>`count(*)`.as('count'),
147+
}).from(this.generic)
148+
.where(query.where)
149+
150+
return pgres[0].count;
151+
}
152+
139153
async list(query: GenericListInput = {}): Promise<GenericList<InferSelectModel<T>>> {
140154
const order = query.order && query.order === 'desc' ? desc : asc;
141155
const orderBy = order(query.sort ? this.key(query.sort) : this.requiredPrimaryKey());

0 commit comments

Comments
 (0)