Skip to content

feat: add first_or_fail to QueryBuilder and Model - #61

Merged
tmgbedu merged 2 commits into
mainfrom
feat/first-or-fail
May 21, 2026
Merged

feat: add first_or_fail to QueryBuilder and Model#61
tmgbedu merged 2 commits into
mainfrom
feat/first-or-fail

Conversation

@tmgbedu

@tmgbedu tmgbedu commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds QueryBuilder.first_or_fail(columns=None) — raises ModelNotFoundException when first() returns None
  • Adds Model.first_or_fail(columns=None) — class-level shortcut delegating to the builder
  • Adds 4 test cases covering: found record, no match, 404 status code, and empty table

Usage

# raises ModelNotFoundException if no match
user = await User.where("email", email).first_or_fail()

# or via the builder
user = await User.query().where("is_admin", True).first_or_fail()

Test plan

  • test_first_or_fail_returns_model_when_found
  • test_first_or_fail_raises_when_no_match
  • test_first_or_fail_exception_has_404_status
  • test_first_or_fail_class_method_raises_when_table_empty

🤖 Generated with Claude Code

tmgbedu and others added 2 commits May 21, 2026 16:01
Raises ModelNotFoundException when no record matches the query chain,
mirroring find_or_fail but for arbitrary where conditions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tmgbedu
tmgbedu merged commit d28d65c into main May 21, 2026
3 checks passed
@tmgbedu
tmgbedu deleted the feat/first-or-fail branch May 22, 2026 04:53
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.

1 participant