Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typeorm): use limit/offset instead of take/skip #475

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ export class BaseService<E extends Node> {
};
}

qb = qb.take(pageOptions.limit || DEFAULT_LIMIT);
qb = qb.limit(pageOptions.limit || DEFAULT_LIMIT);

if (pageOptions.offset) {
qb = qb.skip(pageOptions.offset);
qb = qb.offset(pageOptions.offset);
}

if (fields) {
Expand Down
119 changes: 119 additions & 0 deletions src/test/functional/__snapshots__/server.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,125 @@ Array [
]
`;

exports[`server find: string query: contains \`A\` (upper or lower) with offset 1`] = `
Array [
Object {
"stringField": "AMET QUI",
},
Object {
"stringField": "maiores praesentium",
},
Object {
"stringField": "KAELYN",
},
Object {
"stringField": "alias sint",
},
Object {
"stringField": "molestiae praesentium",
},
Object {
"stringField": "Okuneva",
},
Object {
"stringField": "hartmann",
},
Object {
"stringField": "raquel",
},
Object {
"stringField": "quas fugit",
},
Object {
"stringField": "quia et",
},
Object {
"stringField": "ut consequatur",
},
Object {
"stringField": "iusto perspiciatis",
},
Object {
"stringField": "HAMILL",
},
Object {
"stringField": "LABORE CULPA",
},
Object {
"stringField": "VERITATIS EIUS",
},
Object {
"stringField": "HELGA",
},
Object {
"stringField": "ipsum voluptas",
},
Object {
"stringField": "linnea",
},
Object {
"stringField": "madison",
},
Object {
"stringField": "NUMQUAM ALIQUAM",
},
Object {
"stringField": "macy",
},
Object {
"stringField": "GERLACH",
},
Object {
"stringField": "padberg",
},
Object {
"stringField": "ENIM DICTA",
},
Object {
"stringField": "amalia",
},
Object {
"stringField": "QUAS PERSPICIATIS",
},
Object {
"stringField": "Williamson",
},
Object {
"stringField": "schamberger",
},
Object {
"stringField": "Jared",
},
Object {
"stringField": "QUIDEM FUGIAT",
},
Object {
"stringField": "MAGNAM REICIENDIS",
},
Object {
"stringField": "jaskolski",
},
Object {
"stringField": "BAUCH",
},
Object {
"stringField": "paucek",
},
Object {
"stringField": "VOLUPTATE ATQUE",
},
Object {
"stringField": "placeat voluptate",
},
Object {
"stringField": "pagac",
},
Object {
"stringField": "eius necessitatibus",
},
]
`;

exports[`server find: string query: contains \`a\` (upper or lower) 1`] = `
Array [
Object {
Expand Down
16 changes: 15 additions & 1 deletion src/test/functional/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ describe('server', () => {
expect(result).toMatchSnapshot();
});

test('find: string query: contains `A` (upper or lower) with offset', async () => {
expect.assertions(2);

const result = await binding.query.kitchenSinks(
{ where: { stringField_contains: 'A' }, limit: 100, offset: 20 },
'{ stringField }'
);

expect(result.length).toEqual(38);
expect(result).toMatchSnapshot();
});

test('find: string query: starts with `b` (upper or lower)', async () => {
expect.assertions(2);

Expand Down Expand Up @@ -667,7 +679,9 @@ describe('server', () => {
)
);

expect(result.message).toBe('null value in column "name" violates not-null constraint');
expect(result.message).toBe(
'null value in column "name" of relation "dishs" violates not-null constraint'
);

let savedDishes: Dish[] = [];
try {
Expand Down