CodeDredd / pinia-orm

The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
https://pinia-orm.codedredd.de/
MIT License
444 stars 38 forks source link

[Feature Request] Add updateOrCreate/firstOrCreate #1833

Open vesper8 opened 4 months ago

vesper8 commented 4 months ago

Describe the feature

These are some of the most-used eloquent helpers in Laravel, I personally use updateOrCreate a lot and it would be nice to have it in pinia-orm so I don't have to do things like this:

        if (useRepo(Requirement).find(id)) {
          await useRepo(Requirement)
            .whereId(id) //
            .update(this.form);
        } else {
          await useRepo(Requirement).save({
            id: useRepo(Requirement).all().length + 1, //
            ...this.form,
          });
        }

Additional information

Final checks