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

Adds support for collection filtering #12

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

charlieknoll
Copy link
Contributor

No description provided.

@dannyconnell
Copy link
Collaborator

Thanks @charlieknoll. Can you please explain what is going on with this? What does the functionality do? How would it be used by the end user?

@charlieknoll
Copy link
Contributor Author

Hi @dannyconnell, I was helping a friend out who was "querying" a collection of users for a user and then "querying" another collection of orders for that user. Currently localbase would support this:

  .doc({id: 1}).get().then(user => {
    const u = user
    db.collection('orders')
      .get().then(orders => {
         const userOrders = orders.filter(o=>o.userId == u.id)
         u.orders = userOrders
         console.log(u)
      })
  })

But with the pull request implemented he could do this:

  db.collection('users')
  .doc({id: 1}).get().then(user => {
    const u = user
   db.collection('orders')
      .get({keys: false, filter: {userId: u.id}}).then(orders => { 
       u.orders = orders
       console.log(u)
      })
  })

Looking at the code, I believe it would be more performant for large collections.

BTW, congratulations on your success with fudget!

I really enjoyed your PWA course. I felt your pain in the dev experience with clearing cache, refresh, refresh, etc. It inspired me to create a new dev tool called AppYoke. It's early going but you can check it out on my github.

@ckng
Copy link

ckng commented Jan 12, 2021

Tested working to filter the collection by other fields.

@ckng
Copy link

ckng commented Jan 13, 2021

Another alternative is to change get() to work similarly and consistently with the rest of the APIs. So get() should return all matched documents instead of only one result. But this will likely break backward compatibility. Or maintain get() for returning the first matched result and introduce a getAll() for all matched results.

db.collection('users').doc({ gender: 'male' }).getAll()
// [
// { id: 1, name: 'Bill', age: 47 }
// { id: 2, name: 'Paul', age: 34 }
// ]

e.g. set(), update(), delete() matched all:

db.collection('users').doc({ gender: 'male' }).delete()

if more than one document is matched by your criteria e.g .doc({ gender: 'male' }) then all matched documents will be deleted.

@jiuck
Copy link

jiuck commented Jul 22, 2021

Please @dannyconnell, would be great to have this functionality.

@zakaria-chahboun
Copy link

@dannyconnell come on man!

Copy link

@Qoyyuum Qoyyuum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that it works.

Copy link

@Wiase9889 Wiase9889 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great implementation...

@samuk190
Copy link
Owner

samuk190 commented Jun 6, 2024

Hi guys, I confirm that its working too, I did several tests on my end. I'll be merging this.

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

Successfully merging this pull request may close these issues.

8 participants