ash icon indicating copy to clipboard operation
ash copied to clipboard

Add `%Ash.Expr{}`, which will be returned from `expr/1`

Open zachdaniel opened this issue 1 year ago • 5 comments

Its not possible to easily tell “did they pass an expression”. You can use Ash.Expr.expr? but that literally traverses the entire value.

I think we can actually change this transparently to end users, since they shouldn’t be manipulating expressions, but we’ll need to adjust a bunch of code to just pass the contained expression by. This will also be useful in disambiguating interfaces.

zachdaniel avatar Apr 29 '24 12:04 zachdaniel

Hi @zachdaniel . Can I help with this one? If so, please share some pointers to help get started.

ghalestrilo avatar Aug 22 '24 18:08 ghalestrilo

That would be great :)

The first thing to be done would be to make the expr/1 return %Ash.Expr{expr: <the_expr>}. Then there will be a whole bunch of places that match on expressions that have to unwrap and/or work for that. To see what those places are, we'd likely have to search for expressions like %Ash.Filter{ and %Ash.Query.BooleanExpression{. Those would need to either update/unwrap the new struct (depending on what they do).

FWIW it's going to be a pretty significant change. But end users won't have to know about it.

zachdaniel avatar Aug 22 '24 18:08 zachdaniel

Awesome, thanks! I'll give it a go and report back

ghalestrilo avatar Aug 22 '24 18:08 ghalestrilo

One thing I noticed: we didn't describe where (at which level of abstraction) this struct should be visible. AFAICT load uses query which in turn uses calculation which finally uses expr - maybe wrapped in something like BooleanExpression. Is this boundary defined?

edit: expand on "where"

ghalestrilo avatar Aug 26 '24 23:08 ghalestrilo

It should be invisible when inspecting 👍

zachdaniel avatar Aug 30 '24 17:08 zachdaniel