Skip to content

Commit e57b91e

Browse files
authored
fix: fix total type in paginate (#228)
<!-- Thank you for your pull request. Please review below requirements. Bug fixes and new features should include tests and possibly benchmarks. Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md 感谢您贡献代码。请确认下列 checklist 的完成情况。 Bug 修复和新功能必须包含测试,必要时请附上性能测试。 Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md --> ##### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] `npm test` passes - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added - [ ] commit message follows commit guidelines ##### Affected core subsystem(s) <!-- Provide affected core subsystem(s). --> ##### Description of change <!-- Provide a description of the change below this comment. --> <!-- - any feature? - close https://github.com/eggjs/egg/ISSUE_URL --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Corrected data type for total count in pagination results to ensure accurate numeric values. - **Tests** - Added a test case to verify accurate total count in pagination results. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 35ed76f commit e57b91e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

core/dal-runtime/src/DataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class DataSource<T> implements IDataSource<T> {
7777
]);
7878

7979
return {
80-
total: ret[1],
80+
total: Number(ret[1]),
8181
pageNum: currentPage,
8282
rows: ret[0].map(t => TableModelInstanceBuilder.buildInstance(this.tableModel, t)),
8383
};

core/dal-runtime/test/DataSource.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,8 @@ describe('test/Datasource.test.ts', () => {
146146
$id: insertResult.insertId,
147147
});
148148
assert.equal(findRow2, null);
149+
150+
const res = await dataSource.paginate('findByPrimary', {}, 1, 10);
151+
assert(res.total === 0);
149152
});
150153
});

0 commit comments

Comments
 (0)