|
| 1 | +# SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs/contributors> |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +defmodule AshGraphql.Test.DataLayer.EtsWithFunctions do |
| 6 | + @moduledoc false |
| 7 | + @behaviour Ash.DataLayer |
| 8 | + |
| 9 | + @ets_with_functions %Spark.Dsl.Section{ |
| 10 | + name: :ets_with_functions, |
| 11 | + describe: "ETS data layer with custom functions for testing", |
| 12 | + schema: [ |
| 13 | + private?: [ |
| 14 | + type: :boolean, |
| 15 | + default: false |
| 16 | + ], |
| 17 | + table: [ |
| 18 | + type: :atom |
| 19 | + ], |
| 20 | + repo: [ |
| 21 | + type: :atom, |
| 22 | + doc: "A fake repo option to simulate AshPostgres pattern" |
| 23 | + ] |
| 24 | + ] |
| 25 | + } |
| 26 | + |
| 27 | + use Spark.Dsl.Extension, |
| 28 | + sections: [@ets_with_functions] |
| 29 | + |
| 30 | + @impl true |
| 31 | + defdelegate can?(resource, feature), to: Ash.DataLayer.Ets |
| 32 | + |
| 33 | + @impl true |
| 34 | + defdelegate resource_to_query(resource, domain), to: Ash.DataLayer.Ets |
| 35 | + |
| 36 | + @impl true |
| 37 | + defdelegate limit(query, limit, resource), to: Ash.DataLayer.Ets |
| 38 | + |
| 39 | + @impl true |
| 40 | + defdelegate offset(query, offset, resource), to: Ash.DataLayer.Ets |
| 41 | + |
| 42 | + @impl true |
| 43 | + defdelegate add_calculations(query, calculations, resource), to: Ash.DataLayer.Ets |
| 44 | + |
| 45 | + @impl true |
| 46 | + defdelegate add_aggregate(query, aggregate, resource), to: Ash.DataLayer.Ets |
| 47 | + |
| 48 | + @impl true |
| 49 | + defdelegate set_tenant(resource, query, tenant), to: Ash.DataLayer.Ets |
| 50 | + |
| 51 | + @impl true |
| 52 | + defdelegate set_context(resource, query, context), to: Ash.DataLayer.Ets |
| 53 | + |
| 54 | + @impl true |
| 55 | + defdelegate select(query, select, resource), to: Ash.DataLayer.Ets |
| 56 | + |
| 57 | + @impl true |
| 58 | + defdelegate filter(query, filter, resource), to: Ash.DataLayer.Ets |
| 59 | + |
| 60 | + @impl true |
| 61 | + defdelegate sort(query, sort, resource), to: Ash.DataLayer.Ets |
| 62 | + |
| 63 | + @impl true |
| 64 | + defdelegate distinct(query, distinct, resource), to: Ash.DataLayer.Ets |
| 65 | + |
| 66 | + @impl true |
| 67 | + defdelegate distinct_sort(query, distinct_sort, resource), to: Ash.DataLayer.Ets |
| 68 | + |
| 69 | + @impl true |
| 70 | + defdelegate run_query(query, resource), to: Ash.DataLayer.Ets |
| 71 | + |
| 72 | + @impl true |
| 73 | + defdelegate run_aggregate_query(query, aggregates, resource), to: Ash.DataLayer.Ets |
| 74 | + |
| 75 | + @impl true |
| 76 | + defdelegate create(resource, changeset), to: Ash.DataLayer.Ets |
| 77 | + |
| 78 | + @impl true |
| 79 | + defdelegate destroy(resource, changeset), to: Ash.DataLayer.Ets |
| 80 | + |
| 81 | + @impl true |
| 82 | + defdelegate update(resource, changeset), to: Ash.DataLayer.Ets |
| 83 | + |
| 84 | + @impl true |
| 85 | + defdelegate combination_of(combinations, resource, domain), to: Ash.DataLayer.Ets |
| 86 | + |
| 87 | + @impl true |
| 88 | + defdelegate prefer_lateral_join_for_many_to_many?, to: Ash.DataLayer.Ets |
| 89 | + |
| 90 | + @impl true |
| 91 | + defdelegate calculate(resource, expressions, context), to: Ash.DataLayer.Ets |
| 92 | + |
| 93 | + @impl true |
| 94 | + def functions(resource) do |
| 95 | + # Simulate AshPostgres pattern: access a DSL option, then call a method on it |
| 96 | + # AshPostgres does: AshPostgres.DataLayer.Info.repo(resource, :mutate).config() |
| 97 | + repo = Spark.Dsl.Extension.get_opt(resource, [:ets_with_functions], :repo, nil, true) |
| 98 | + |
| 99 | + if repo do |
| 100 | + _config = repo.config() |
| 101 | + end |
| 102 | + |
| 103 | + [AshGraphql.Test.Functions.TestILike] |
| 104 | + end |
| 105 | +end |
0 commit comments