vapor / fluent-kit

Swift ORM (queries, models, and relations) for NoSQL and SQL databases
MIT License
218 stars 116 forks source link

Enforce correct @ID(key:) usage at compile time #554

Closed gwynne closed 1 year ago

gwynne commented 1 year ago

Using @ID(key:) with a key other than .id or a value that is not a UUID is now a compile-time error instead of a runtime crash.

Additional changes:

⚠️ IMPORTANT ⚠️

  1. Incorrect usage of @ID(key: "...") with any string other than "id" will still trigger a fatal error at runtime as well as the deprecation warning. This is unavoidable without a source-breaking change, since the contents of the string can not be checked at compile time.
  2. Incorrect usage of @ID where the type of the property is not UUID - for example, @ID var id: Int? - usually results in the extremely unhelpful compiler error "Type of expression is ambiguous without more context." Unfortunately, there doesn't seem to be a way to make this less opaque at the moment.
codecov-commenter commented 1 year ago

Codecov Report

Merging #554 (b877d08) into main (636a59e) will increase coverage by 0.02%. The diff coverage is 68.18%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #554 +/- ## ========================================== + Coverage 47.12% 47.14% +0.02% ========================================== Files 106 106 Lines 6154 6147 -7 ========================================== - Hits 2900 2898 -2 + Misses 3254 3249 -5 ``` | [Impacted Files](https://codecov.io/gh/vapor/fluent-kit/pull/554?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor) | Coverage Δ | | |---|---|---| | [Sources/FluentKit/Properties/ID.swift](https://codecov.io/gh/vapor/fluent-kit/pull/554?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9GbHVlbnRLaXQvUHJvcGVydGllcy9JRC5zd2lmdA==) | `81.00% <45.45%> (+2.62%)` | :arrow_up: | | [Sources/FluentKit/Model/MirrorBypass.swift](https://codecov.io/gh/vapor/fluent-kit/pull/554?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9GbHVlbnRLaXQvTW9kZWwvTWlycm9yQnlwYXNzLnN3aWZ0) | `76.71% <90.90%> (+1.35%)` | :arrow_up: |
VaporBot commented 1 year ago

These changes are now available in 1.40.0