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

total in pagination is a string #339

Closed
moltar opened this issue May 4, 2018 · 9 comments
Closed

total in pagination is a string #339

moltar opened this issue May 4, 2018 · 9 comments
Assignees

Comments

@moltar
Copy link

moltar commented May 4, 2018

Database: Postgres

Using pagination and the total field is returned as a string, where all the rest of the pagination values are a number.

{"total":"74","perPage":20,"page":1,"lastPage":4,  ....
@thetutlage
Copy link
Member

@moltar
Copy link
Author

moltar commented May 5, 2018

Yes, I had the feeling it was to do with bigints.

Do you think we should maybe handle this case somehow? I think the cases where someone would have a bigint are super small, and everyone suffers from that. Maybe we could detect normal ints and then convert the number to int, and for bigints leave as a string (or wrap in a bigint lib).

But at a minimum, I think this should be documented. As the docs show the total being an int.

@thetutlage
Copy link
Member

Agree, it must be in the documentation.

Detecting and converting behind the scenes is not a good idea, since you are modifying the input and people never know, whether to expect a number of a string.

@moltar
Copy link
Author

moltar commented May 7, 2018

Maybe a config option, at least? It's pretty tedious to wrap every output just to change total to a number. For most projects I just know I won't have a bigint issue. It'd be a good problem to have :)

@moltar
Copy link
Author

moltar commented May 7, 2018

I'm wondering if this would be possible via a custom serializer? Does serializer apply to pagination meta data too?

@thetutlage
Copy link
Member

If a value is a bigInt and you try to read it as a number, then it be corrupted at the first place before you can transform it to string.

You can read more about bigInts issue with Javascript in general.

I am happy accepting PR for the docs though

@moltar
Copy link
Author

moltar commented May 8, 2018

If a value is a bigInt and you try to read it as a number, then it be corrupted at the first place before you can transform it to string.

Yeah, I am aware. But I don't care about bigint for 99% of projects. They'll never reach that level of data. I am just trying to solve it for myself. Not saying it needs to be part of core. Just trying to find a good solution which does not require unwraping and re-casting every database response.

I am just thinking out-loud re customer serializers. Is it something that can be applied in this case? If we have a clear path to solving it, I'll document it too.

@thetutlage
Copy link
Member

thetutlage commented May 8, 2018

In that case, what you can do is use the pg library types parser. brianc/node-postgres#353 (comment) and https://github.com/brianc/node-pg-types

@borie88
Copy link

borie88 commented Jun 28, 2018

I've had this issue in all of my projects. Only the "page" value is a string though. Using mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants