Skip to content

Commit

Permalink
Update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Mar 15, 2024
1 parent 62734fa commit 0255f95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

## Version History

$## v17.1.0

- :rocket: Add generic `.count()` function

### v17.0.1

- :arrow_up: Update Core Deps
Expand Down
14 changes: 14 additions & 0 deletions generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export type GenericListInput = {
where?: SQL<unknown>;
}

export type GenericCountInput = {
order?: GenericListOrder;
where?: SQL<unknown>;
}

export type GenericStreamInput = {
where?: SQL<unknown>;
}
Expand Down Expand Up @@ -136,6 +141,15 @@ export default class Drizzle<T extends GenericTable> {
return generic;
}

async count(query: GenericCountInput = {}): Promise<number> {
const pgres = await this.pool.select({
count: sql<number>`count(*)`.as('count'),
}).from(this.generic)
.where(query.where)

return pgres[0].count;
}

async list(query: GenericListInput = {}): Promise<GenericList<InferSelectModel<T>>> {
const order = query.order && query.order === 'desc' ? desc : asc;
const orderBy = order(query.sort ? this.key(query.sort) : this.requiredPrimaryKey());
Expand Down

0 comments on commit 0255f95

Please sign in to comment.