From 9047fbd2eeb61493cfdd7c637a0e43534f6c76ee Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sat, 19 Nov 2022 13:19:26 -0500 Subject: [PATCH] improvement: add `where` and `or_where` to expr --- lib/ash/expr/expr.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/ash/expr/expr.ex b/lib/ash/expr/expr.ex index 133b26aa..5486e022 100644 --- a/lib/ash/expr/expr.ex +++ b/lib/ash/expr/expr.ex @@ -4,6 +4,24 @@ defmodule Ash.Expr do @type t :: any + defmacro where(left, right) do + left = do_expr(left) + right = do_expr(right) + + quote do + Ash.Expr.expr(unquote(left) and unquote(right)) + end + end + + defmacro or_where(left, right) do + left = do_expr(left) + right = do_expr(right) + + quote do + Ash.Expr.expr(unquote(left) or unquote(right)) + end + end + defmacro expr(do: body) do quote location: :keep do Ash.Expr.expr(unquote(body))