Skip to content

Commit 9bfe290

Browse files
test: Fix the typeorm tests with negative fetch and my sql
1 parent fc5cbb0 commit 9bfe290

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/query-typeorm/src/services/typeorm-query.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
UpdateOneOptions
2121
} from '@ptc-org/nestjs-query-core'
2222
import { DeleteResult, FindOptionsWhere, Repository } from 'typeorm'
23+
import { DriverUtils } from 'typeorm/driver/DriverUtils'
2324
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'
2425
import { UpdateResult } from 'typeorm/query-builder/result/UpdateResult'
2526

@@ -55,6 +56,8 @@ export class TypeOrmQueryService<Entity>
5556

5657
readonly useSoftDelete: boolean
5758

59+
private readonly isMySQL: boolean
60+
5861
constructor(
5962
readonly repo: Repository<Entity>,
6063
opts?: TypeOrmQueryServiceOpts<Entity>
@@ -63,6 +66,8 @@ export class TypeOrmQueryService<Entity>
6366

6467
this.filterQueryBuilder = opts?.filterQueryBuilder ?? new FilterQueryBuilder<Entity>(this.repo)
6568
this.useSoftDelete = opts?.useSoftDelete ?? false
69+
70+
this.isMySQL = DriverUtils.isMySQLFamily(repo.manager.connection.driver)
6671
}
6772

6873
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -84,6 +89,9 @@ export class TypeOrmQueryService<Entity>
8489
* @param query - The Query used to filter, page, and sort rows.
8590
*/
8691
public async query(query: Query<Entity>, opts?: QueryOptions<Entity>): Promise<Entity[]> {
92+
if (this.isMySQL && query.paging.offset && !query.paging?.limit) {
93+
query = { ...query, paging: { ...query.paging, limit: Number.MAX_SAFE_INTEGER } }
94+
}
8795
const qb = this.filterQueryBuilder.select(query)
8896

8997
if (opts?.withDeleted) {

0 commit comments

Comments
 (0)