Closed rwillians closed 1 year ago
@rwillians my current preference is to keep selectors as simple as possible. There are a number of places where selector is used where we can't use an arbitrary query in place of a selector. I can't remember where off the top of my head.
We do support dropping down to a regular %Ecto.Query
in cases where we want more complex behaviors.
If there is an Ecto query, Derive assumes it's an update statement and runs it as-is.
For example: https://github.com/TurtleAI/turtle-api/blob/master/lib/turtle/project/reducer.ex#L96-L122
How we handle Turtle.Event.CardDeleted
is most similar to what you're trying to accomplish.
LMK if that works. If not can re-open.
Derive.Ecto.Selector
should accept a%Query{}
(ideally, any query-able supported by Ecto) as selector. https://github.com/TurtleAI/derive/blob/master/lib/derive/ecto/selector.ex#L23-L31A common use case is changing multiple rows with a single query. For example:
A possible implementation (in https://github.com/TurtleAI/derive/blob/master/lib/derive/ecto/selector.ex#L23-L31) is:
Doing multiple operations is likely -- although I didn't measure it -- performance impact.