samuk190 / localbase

A Firebase-Style Database ... Offline!
636 stars 84 forks source link

how do I get collection length? #50

Open sarwarcse opened 3 years ago

sarwarcse commented 3 years ago

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"});
teamsuperpanda commented 2 years ago

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.

Jargonius commented 2 years ago

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.

samuk190 commented 2 months ago

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.

It's possible I'll look into it