pinia-orm icon indicating copy to clipboard operation
pinia-orm copied to clipboard

[Feature Request] whereLike

Open vesper8 opened this issue 2 years ago • 2 comments

Describe the feature

While we wait for the possibility of https://github.com/vuex-orm/plugin-search being ported to pinia-orm..

I tried doing something like this:

useRepo(Project).query().where('name', 'like', `%${this.query}%`).get();

I didn't get any errors, but it also didn't work.

It would be nice if you could add a whereLike helper.

I ended up going with this

useRepo(Project).query().where('name', (value) => {
  return value.toLowerCase().includes(this.query.toLowerCase());
}).get();

Which works well enough..

Thanks!

Additional information

  • [X] Would you be willing to help implement this feature?

Final checks

vesper8 avatar Sep 20 '23 14:09 vesper8

I can try to add the keyword like to where clause. But i don't think i add a helper for it because i am orientanting on laravel syntax. And laravel doesn't have it.

CodeDredd avatar Jan 16 '24 21:01 CodeDredd

As you wish. I've been using a whereLike macro in Laravel for many years now.. originally made popular through Spatie's twitter account.

For pinia-orm I ended up going for something like this:


    filteredPosts() {
      const query = useRepo(Post).query();

      let results = [];

      if (this.query.length >= this.minQuery) {
        query.where('title', (value) => {
          return value.toLowerCase().includes(this.query.toLowerCase());
        });

        results = query.get();

        this.queryResults.posts = results.length;
      }

      return results;
    },

But this clearly is nowhere near as convenient or versatile as vuex-orm's search plugin

vesper8 avatar Jan 17 '24 00:01 vesper8