WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

startsWith condition for query

Open kafkas opened this issue 7 years ago • 4 comments

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?

kafkas avatar Jan 05 '19 01:01 kafkas

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%"))

rkrajewski avatar Jan 05 '19 14:01 rkrajewski

Thank you so much.

kafkas avatar Jan 05 '19 19:01 kafkas

@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"

radex avatar Jan 10 '19 16:01 radex

@radex Sure will do.

kafkas avatar Jan 10 '19 18:01 kafkas