File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 10
10
11
11
## Version History
12
12
13
+ $## v17.1.0
14
+
15
+ - :rocket : Add generic ` .count() ` function
16
+
13
17
### v17.0.1
14
18
15
19
- :arrow_up : Update Core Deps
Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ export type GenericListInput = {
38
38
where ?: SQL < unknown > ;
39
39
}
40
40
41
+ export type GenericCountInput = {
42
+ order ?: GenericListOrder ;
43
+ where ?: SQL < unknown > ;
44
+ }
45
+
41
46
export type GenericStreamInput = {
42
47
where ?: SQL < unknown > ;
43
48
}
@@ -136,6 +141,15 @@ export default class Drizzle<T extends GenericTable> {
136
141
return generic ;
137
142
}
138
143
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
+
139
153
async list ( query : GenericListInput = { } ) : Promise < GenericList < InferSelectModel < T > > > {
140
154
const order = query . order && query . order === 'desc' ? desc : asc ;
141
155
const orderBy = order ( query . sort ? this . key ( query . sort ) : this . requiredPrimaryKey ( ) ) ;
You can’t perform that action at this time.
0 commit comments