Closed Alenar closed 1 month ago
3 files ±0 43 suites ±0 8m 35s :stopwatch: +10s 992 tests +1 992 :white_check_mark: +1 0 :zzz: ±0 0 :x: ±0 1 090 runs +1 1 090 :white_check_mark: +1 0 :zzz: ±0 0 :x: ±0
Results for commit c3a60e67. ± Comparison against base commit 8b66e454.
:recycle: This comment has been updated with latest results.
Content
This PR includes a refactor of the database API used to query entities from the database.
As of today we used the
Provider
trait to encapsulate a entity query, this trait come with a major issue: it needs to borrow a connection to the database, making it difficult to return a iterator to a query result. This PR replace this trait with a new one:Query
. Basically a query is what was a provider but instead of owning a reference to a database connection it own aWhereCondition
that will be applied when this query is run.This means that a query implementation can't run itself like the provider could, instead you use an extension method directly on the sql connection:
fetch
. This method take a query as a parameter and nothing more since it own the where condition to applyWhen we doesn't need the iterator returned by
fetch
there's two new other extension method on the db connection that are available:fetch_one
: return the first result of the iterator if anyfetch_and_collect
: that collect the iterator into the desired container (like a iterator.collect do).Query design philosophy
All implementation have been made using the following model
This is at creation, and by the query itself, that the condition is defined:
Caveat: This system make it more difficult to chain conditions outside of the query (like in the repository). This is only visible in the changes to the
OpenMessageRepository
and its associated 'Get' queries but it may be cumbersome if we want to multiply such uses.Usage
Before:
After:
Pre-submit checklist
Comments
Caveat:
Query::get_definition
method could lose its condition parameter and pull it up directly fromQuery::filter
. But this would mean cloning the stored definition twice (one to get the filter sql expression needed and one to get the condition values infetch
). We may have to rethink theWhereCondition
if we want to address that issue.Issue(s)
Closes #1711