localbase
localbase copied to clipboard
how do I get collection length?
if there is a table named customer. then how can I get the counter of total customers.
Another scenario is : if I have multiple status of customer, where active customer is more then 100. I want to show the counter of total active customer but I will get 10 rows of 100; I want to make a response like this :
let response ={
total_rows:100,
row_limit:10,
total_page:10,
current_page:1, // it means 0 to 10 positions data
rows:[{1},{},....{10}]
};
//db.collection('customers').doc({status:"active"});
For the counter I just grab the collection and assign it to a variable. Using variablename.length you get how many objects (in this case customers) there are.
Localbase is similar to Firebase but I haven't seen in the docs anything about how to handle limiting docs into groups. You can limit to 50 but it only returns the first 50. I can't help you with fetching 50+ and limiting from there but because it is local you could use vuex or even just a function to return what you need.
I also would like to be able to get count or length much like in SQL. I don't know if it's the same here but I'm SQL is faster to call count than to get all the records and get the length of the result.