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