[codex] Finalize returned SQLite queries - #4
Draft
wtsnz wants to merge 2 commits into
Draft
Conversation
Implement the Ash data-layer return_query/2 callback for AshSqlite by delegating returned Ecto queries through AshSql.Query.return_query/2 after applying default SQL bindings. Normal reads already finalize queries in run_query/2 before execution, but callers that ask Ash for the data-layer query need the same finalization so stored sorts and related query rewrites are visible in the returned Ecto query. Add a regression test that a sorted Ash query returned through Ash.Query.data_layer_query/1 includes the expected ORDER BY clause.
Drop the dedicated SQL-shape regression test from the return_query callback PR. AshPostgres has the same callback without a direct return_query test, so keep this PR focused on mirroring the data-layer behavior and leave broader returned-query coverage to follow-up aggregate work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds
AshSqlite.DataLayer.return_query/2and delegates returned Ecto queries through the sharedAshSql.Query.return_query/2path after applying the normal Ash SQL bindings.Why
I ran into this while looking into generated SQLite queries from Ash. Normal reads go through
run_query/2, where AshSqlite has a chance to finalize the query before it executes. But callers that ask Ash for the data-layer query directly do not go through that execution path.That means some query state that has been collected in Ash SQL bindings, such as sort/finalization state, can be left unapplied on the returned Ecto query.
I check and AshPostgres already has this same callback shape, so I figured it makes sense to bring AshSqlite into line with that behaviour.
Validation
MIX_ENV=test mix testmix format --check-formatted lib/data_layer.ex test/sort_test.exs