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

getCount when using take #9662

Open
shellking4 opened this issue Dec 28, 2022 · 4 comments
Open

getCount when using take #9662

shellking4 opened this issue Dec 28, 2022 · 4 comments

Comments

@shellking4
Copy link

I have a behavior in typeorm lately. Here is my query :

            queryBuilder.where("ticket.code ILIKE :code", { code: `%${searchString}%` })
                .orWhere("ticket.encryptedCode ILIKE :encryptedCode", { encryptedCode: `%${searchString}%` },)
                .orWhere("payment.transaction ILIKE :transaction", { transaction: `%${searchString}%` },)
                .orWhere("payment.caissier ILIKE :cashier", { cashier: `%${searchString}%` },)
                .orWhere("gate.number ILIKE :gateNumber", { gateNumber: `%${searchString}%` },);
        }))
            .skip(skip)
            .take(dataLength)
            .getManyAndCount();

const dataCount = query[1]

I expect to have dataCount === dataLength but it's not the case. Instead the number of elements selected by the query before applying take is returned. Is this the way it works or what is going on in here ?

@iJhefe
Copy link
Contributor

iJhefe commented Dec 28, 2022

"getCount" doesnt consider the parameters "take" and "skip"

@rubber-bird
Copy link

rubber-bird commented Jan 21, 2023

As mentioned on previous response you can count those which you need without take or skip, because these functions in query builder is generated it omits these clauses. you can select those which you need and then use length method of returned array.

@shellking4
Copy link
Author

Thank y'all for your replies. It is something I really didn't know of. It was seeming so weird to me. Now that I know I'll be careful next time

@shellking4
Copy link
Author

As mentioned on previous response you can count those which you need without take or skip, because these functions in query builder is generated it omits these clauses. you can select those which you need and then use length method of returned array.

Thank you @rubber-bird. This is what I did finally. Thank you very much

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

3 participants