pocketbase / js-sdk

PocketBase JavaScript SDK
https://www.npmjs.com/package/pocketbase
MIT License
2.06k stars 122 forks source link

Feature: Add count method to the sdk #285

Closed JustDenP closed 5 months ago

JustDenP commented 5 months ago

Hello, pocketbase is an excellent solution, on which I have already made several medium-sized applications, but each time I am faced with a single, but important inconvenience - the absence of a count method, which would display the total number using a filter.

For example pb.collection('posts').count({ filter: 'id = "123"' })

This is a simple example, there are more complex ones, and creating a view table every time for dozens of cases is very inconvenient, and getting total via getFullList is not rational, because it returns the entire array, but half of the time I want only the total number.

If such a method were added, it would make life a lot easier

ganigeorgiev commented 5 months ago

At least for now I'm not planning adding a dedicated count or other similar method as it will be too limited and confusing if users want to apply a more advanced aggregation.

If you just want the total number of items you can invoke:

const { totalItems } = await pb.collection("posts").getList(1, 1)