cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
54 stars 23 forks source link

Fix caching for insert queries with fragments #177

Closed msmakouz closed 6 months ago

msmakouz commented 6 months ago

What's was changed

The caching of insert queries with fragments has been fixed.

The hash of the cached query did not take into account the number of fragments used in the query. That is, if in the first query we use two fragments, its hash is generated and we save the generated query:

$insert = $database->insert()->into('table')->values([
    'name' => 'John Doe',
    'updated_at' => new Expression('NOW()'),
    'deleted_at' => new Expression('NOW()'),
]);

Then comes a query where the number of fragments is different; its generated hash will be the same, but the generated SQL will be different:

$insert = $database->insert()->into('table')->values([
    'name' => 'John Doe',
    'updated_at' => new Expression('NOW()'),
    'deleted_at' => null,
]);

Another situation may occur where the number of fragments is the same, but their content is different. This has been fixed. Now the query hash takes into account the fragments and their content.

Closes: #176

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.27%. Comparing base (9eb6669) to head (3c50583).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## 2.x #177 +/- ## ============================================ + Coverage 95.25% 95.27% +0.02% - Complexity 1838 1839 +1 ============================================ Files 130 130 Lines 5075 5077 +2 ============================================ + Hits 4834 4837 +3 + Misses 241 240 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.