vapor / fluent-kit

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

Generate deterministic column ordering in insert and update queries #557

Closed gwynne closed 1 year ago

gwynne commented 1 year ago

This is an updated version of #556 by @rausnitz which updates the generation of INSERT queries to be both deterministic and more performant by eliding pointless repetition of the Fluent -> SQL conversion of the field list.

Additional kudos for @rausnitz for his enthusiasm, which inspired me to take another hard look at the existing logic!

Closes #543

gwynne commented 1 year ago

@rausnitz As in your original PR, I only implemented this logic for INSERT queries specifically, but UPDATE queries are also affected by the same issue. The same trick can be applied there as well, if it would be of additional benefit for your use case. (Fortunately SELECT queries already base their ordering on the fields, and DELETE queries don't specify columns at all.)

Edit: Went ahead and did it for UPDATE queries too. Might as well be consistent.

codecov-commenter commented 1 year ago

Codecov Report

Merging #557 (a4d7d5c) into main (0fdeff6) will increase coverage by 0.09%. The diff coverage is 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #557 +/- ## ========================================== + Coverage 46.91% 47.00% +0.09% ========================================== Files 106 106 Lines 6201 6204 +3 ========================================== + Hits 2909 2916 +7 + Misses 3292 3288 -4 ``` | [Impacted Files](https://codecov.io/gh/vapor/fluent-kit/pull/557?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor) | Coverage Δ | | |---|---|---| | [Sources/FluentSQL/SQLQueryConverter.swift](https://codecov.io/gh/vapor/fluent-kit/pull/557?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9GbHVlbnRTUUwvU1FMUXVlcnlDb252ZXJ0ZXIuc3dpZnQ=) | `80.53% <100.00%> (+1.23%)` | :arrow_up: |
VaporBot commented 1 year ago

These changes are now available in 1.42.2