Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

startsWith condition for query #196

Closed kafkas closed 5 years ago

kafkas commented 5 years ago

I was going through the Query docs and didn't come across a startsWith condition. Something that can be used a lot for things like

usersCollection.query(
        Q.where("username", Q.sw("ja")),
        Q.or(Q.where("full_name", Q.sw("ja")))
    )

Is there native support for this or do I have to query all users and then do the filtering with JS, which doesn't sound very efficient?

rkrajewski commented 5 years ago

You can use like operator (https://github.com/Nozbe/WatermelonDB/blob/master/docs/Query.md#conditions-with-other-operators):

Q.where("full_name", Q.like("John%"))
kafkas commented 5 years ago

Thank you so much.

radex commented 5 years ago

@anarkafkas It would be awesome if you could send a quick pull request with a documentation update — since it's clearly not obvious that one can use Q.like as "startsWith"

kafkas commented 5 years ago

@radex Sure will do.