From 13413d3cc7dc89d03cdd2600e2d3adc072443aac Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 20 Oct 2022 01:08:35 -0400 Subject: [PATCH] feat: support `now()` in latest Ash --- lib/expr.ex | 23 ++++++++++++++++++++++- mix.exs | 2 +- mix.lock | 2 +- test/support/resources/post.ex | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/expr.ex b/lib/expr.ex index e436463..981d86b 100644 --- a/lib/expr.ex +++ b/lib/expr.ex @@ -4,7 +4,7 @@ defmodule AshPostgres.Expr do alias Ash.Filter alias Ash.Query.{BooleanExpression, Exists, Not, Ref} alias Ash.Query.Operator.IsNil - alias Ash.Query.Function.{Ago, Contains, GetPath, If, Length, Type} + alias Ash.Query.Function.{Ago, Contains, GetPath, If, Length, Now, Type} alias AshPostgres.Functions.{Fragment, TrigramSimilarity} require Ecto.Query @@ -673,6 +673,27 @@ defmodule AshPostgres.Expr do do_dynamic_expr(query, arg1, bindings, embedded?, type) end + defp do_dynamic_expr( + query, + %Now{embedded?: pred_embedded?}, + bindings, + embedded?, + type + ) do + do_dynamic_expr( + query, + %Fragment{ + embedded?: pred_embedded?, + arguments: [ + raw: "now()" + ] + }, + bindings, + embedded?, + type + ) + end + defp do_dynamic_expr( query, %Exists{at_path: at_path, path: [first | rest], expr: expr}, diff --git a/mix.exs b/mix.exs index e267e5c..c274094 100644 --- a/mix.exs +++ b/mix.exs @@ -137,7 +137,7 @@ defmodule AshPostgres.MixProject do {:ecto, "~> 3.9"}, {:jason, "~> 1.0"}, {:postgrex, ">= 0.0.0"}, - {:ash, ash_version("~> 2.0")}, + {:ash, ash_version("~> 2.1")}, {:git_ops, "~> 2.5.1", only: :dev}, {:ex_doc, "~> 0.22", only: :dev, runtime: false}, {:ex_check, "~> 0.14", only: :dev}, diff --git a/mix.lock b/mix.lock index 25acbfb..81bd52d 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "ash": {:hex, :ash, "2.0.0", "c3688a9d2ed384462a6db227ebf7a21db3a7076dec1e5d65f70e59bff0661719", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:spark, "~> 0.1 and >= 0.1.28", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "77bebd78b273d482f9d1436b589946cf879aa4531fee01e55371a0823e079fcd"}, + "ash": {:hex, :ash, "2.1.0", "94a5d78cf5d007a51821e0a837f6d9c7db7ed48ddf154c56097eab3eb3429fd4", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: true]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8.0", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: false]}, {:spark, "~> 0.1 and >= 0.1.28", [hex: :spark, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.5.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c14a4c2864b4c3c18eb3c65bd8768926178a954c61809a318ffcd8b0050bc84"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"}, diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 70ac5dc..b5deae6 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -125,7 +125,7 @@ defmodule AshPostgres.Test.Post do expr( # This is written in a silly way on purpose, to test a regression if( - fragment("(? <= (now() - '1 month'::interval))", created_at), + fragment("(? <= (? - '1 month'::interval))", now(), created_at), true, false )