@@ -185,7 +185,22 @@ export const RepoFor = <
185
185
: { } ;
186
186
}
187
187
188
- protected async paginate (
188
+ protected async paginateAndRun (
189
+ listOfAllQuery : $expr_Select <
190
+ $ . TypeSet < $ . ObjectType < DBName < Root > > , $ . Cardinality . Many >
191
+ > ,
192
+ input : PaginationInput ,
193
+ ) : Promise < PaginatedListType < Dto > > {
194
+ const paginated = this . paginate ( listOfAllQuery , input ) ;
195
+ const query = e . select ( {
196
+ ...paginated ,
197
+ items : e . select ( paginated . items , this . hydrate ) ,
198
+ } ) ;
199
+ const result = await this . db . run ( query ) ;
200
+ return result as any ;
201
+ }
202
+
203
+ protected paginate (
189
204
listOfAllQuery : $expr_Select <
190
205
$ . TypeSet < $ . ObjectType < DBName < Root > > , $ . Cardinality . Many >
191
206
> ,
@@ -195,18 +210,14 @@ export const RepoFor = <
195
210
offset : ( input . page - 1 ) * input . count ,
196
211
limit : input . count + 1 ,
197
212
} ) ) ;
198
- const items = e . select ( thisPage , ( obj : any ) => ( {
199
- ...this . hydrate ( obj ) ,
213
+ const items = e . select ( thisPage , ( ) => ( {
200
214
limit : input . count ,
201
215
} ) ) ;
202
- const query = e . select ( {
216
+ return {
203
217
items : items as any ,
204
218
total : e . count ( listOfAllQuery ) ,
205
219
hasMore : e . op ( e . count ( thisPage ) , '>' , input . count ) ,
206
- } ) ;
207
-
208
- const result = await this . db . run ( query ) ;
209
- return result as PaginatedListType < Dto > ;
220
+ } ;
210
221
}
211
222
212
223
// endregion
@@ -272,7 +283,7 @@ export const RepoFor = <
272
283
...this . applyFilter ( obj , input ) ,
273
284
...this . applyOrderBy ( obj , input ) ,
274
285
} ) ) ;
275
- return await this . paginate ( all as any , input ) ;
286
+ return await this . paginateAndRun ( all as any , input ) ;
276
287
}
277
288
278
289
async create ( input : EasyInsertShape < Root > ) : Promise < Dto > {
0 commit comments