Skip to content

Commit

Permalink
fix: fix total type in paginate (#228)
Browse files Browse the repository at this point in the history
<!--
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 -->
  • Loading branch information
killagu authored Jul 9, 2024
1 parent 35ed76f commit e57b91e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/dal-runtime/src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DataSource<T> implements IDataSource<T> {
]);

return {
total: ret[1],
total: Number(ret[1]),
pageNum: currentPage,
rows: ret[0].map(t => TableModelInstanceBuilder.buildInstance(this.tableModel, t)),
};
Expand Down
3 changes: 3 additions & 0 deletions core/dal-runtime/test/DataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,8 @@ describe('test/Datasource.test.ts', () => {
$id: insertResult.insertId,
});
assert.equal(findRow2, null);

const res = await dataSource.paginate('findByPrimary', {}, 1, 10);
assert(res.total === 0);
});
});

0 comments on commit e57b91e

Please sign in to comment.