Skip to content

feat(pinia-orm): add updateOrCreate & firstOrCreate repository methods#2032

Merged
CodeDredd merged 1 commit into
mainfrom
feat/update-or-create
Jul 20, 2026
Merged

feat(pinia-orm): add updateOrCreate & firstOrCreate repository methods#2032
CodeDredd merged 1 commit into
mainfrom
feat/update-or-create

Conversation

@CodeDredd

Copy link
Copy Markdown
Owner

Feature (#1833)

Laravel-style upsert helpers on the repository:

// return the first user named Jane, or create her with age 40
const user = useRepo(User).firstOrCreate({ name: 'Jane Doe' }, { age: 40 })

// update Jane's age, or create her with the merged attributes
useRepo(User).updateOrCreate({ name: 'Jane Doe' }, { age: 41 })
  • Matching compares every attribute pair with strict equality via a where-closure.
  • updateOrCreate updates through save() using the matched record's primary key (composite keys supported).
  • Docs: new Update Or Create section on the Updating Data guide page.

Tests

7 new tests: create-when-missing, update-when-matching, multi-attribute matching, composite primary keys, uid generation, firstOrCreate both paths. Full suite green.

closes #1833

Laravel-style helpers: firstOrCreate returns the first record matching
the given attributes or persists a new one from the merged attributes
and values. updateOrCreate updates the first matching record with the
given values or creates it.

closes #1833
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.40%. Comparing base (018acee) to head (80b1c12).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2032   +/-   ##
=======================================
  Coverage   99.40%   99.40%           
=======================================
  Files          82       82           
  Lines        3025     3042   +17     
  Branches      533      537    +4     
=======================================
+ Hits         3007     3024   +17     
  Misses         15       15           
  Partials        3        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CodeDredd
CodeDredd merged commit 6a511cb into main Jul 20, 2026
12 of 13 checks passed
@CodeDredd
CodeDredd deleted the feat/update-or-create branch July 20, 2026 15:06
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add updateOrCreate/firstOrCreate

2 participants