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

[Feature Request] whereLike #1692

Open
2 tasks done
vesper8 opened this issue Sep 20, 2023 · 2 comments
Open
2 tasks done

[Feature Request] whereLike #1692

vesper8 opened this issue Sep 20, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@vesper8
Copy link

vesper8 commented Sep 20, 2023

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

  • Would you be willing to help implement this feature?

Final checks

@CodeDredd
Copy link
Owner

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 CodeDredd added enhancement New feature or request and removed pending triage labels Jan 16, 2024
@vesper8
Copy link
Author

vesper8 commented Jan 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants