Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8cadfc9

Browse files
authored
feat: update to ash 1.11 (ash-project#13)
1 parentd6b73f8 commit8cadfc9

File tree

3 files changed

+68
-21
lines changed

3 files changed

+68
-21
lines changed

‎lib/data_layer.ex‎

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ defmodule AshPostgres.DataLayer do
3434
]
3535
}
3636

37+
aliasAsh.DataLayer.Delegate
3738
aliasAsh.Filter
3839
aliasAsh.Filter.{Expression,Not,Predicate}
3940
aliasAsh.Filter.Predicate.{Eq,GreaterThan,In,IsNil,LessThan}
@@ -78,7 +79,21 @@ defmodule AshPostgres.DataLayer do
7879
defcan?(_,:transact),do:true
7980
defcan?(_,:composite_primary_key),do:true
8081
defcan?(_,:upsert),do:true
81-
defcan?(_,:join),do:true
82+
83+
defcan?(resource,{:join,other_resource})do
84+
other_resource=Delegate.get_delegated(other_resource)
85+
data_layer=Ash.Resource.data_layer(resource)
86+
other_data_layer=Ash.Resource.data_layer(other_resource)
87+
data_layer==other_data_layerandrepo(data_layer)==repo(other_data_layer)
88+
end
89+
90+
defcan?(resource,{:lateral_join,other_resource})do
91+
other_resource=Delegate.get_delegated(other_resource)
92+
data_layer=Ash.Resource.data_layer(resource)
93+
other_data_layer=Ash.Resource.data_layer(other_resource)
94+
data_layer==other_data_layerandrepo(data_layer)==repo(other_data_layer)
95+
end
96+
8297
defcan?(_,:boolean_filter),do:true
8398
defcan?(_,{:aggregate,:count}),do:true
8499
defcan?(_,:aggregate_filter),do:true
@@ -130,6 +145,38 @@ defmodule AshPostgres.DataLayer do
130145
{:ok,repo(resource).all(query)}
131146
end
132147

148+
@impltrue
149+
defrun_query_with_lateral_join(
150+
query,
151+
root_data,
152+
source_resource,
153+
_destination_resource,
154+
source_field,
155+
destination_field
156+
)do
157+
source_values=Enum.map(root_data,&Map.get(&1,source_field))
158+
159+
subquery=
160+
subquery(
161+
from(destinationinquery,
162+
where:
163+
field(destination,^destination_field)==
164+
field(parent_as(:source_record),^source_field)
165+
)
166+
)
167+
168+
query=
169+
from(sourceinresource_to_query(source_resource),
170+
as::source_record,
171+
where:field(source,^source_field)in^source_values,
172+
inner_lateral_join:destinationin^subquery,
173+
on:field(source,^source_field)==field(destination,^destination_field),
174+
select:destination
175+
)
176+
177+
{:ok,repo(source_resource).all(query)}
178+
end
179+
133180
@impltrue
134181
defresource_to_query(resource),
135182
do:Ecto.Queryable.to_query({table(resource),resource})
@@ -189,23 +236,23 @@ defmodule AshPostgres.DataLayer do
189236
defsort(query,sort,_resource)do
190237
query=default_bindings(query)
191238

192-
sort_expr=
193-
sort
194-
|>sanitize_sort()
195-
|>Enum.map(fn{order,sort}->
196-
binding=
197-
caseMap.fetch(query.__ash_bindings__.aggregates,sort)do
198-
{:ok,binding}->
199-
binding
200-
201-
:error->
202-
0
203-
end
204-
205-
{order,{{:.,[],[{:&,[],[binding]},sort]},[],[]}}
206-
end)
207-
208-
{:ok,%{query|order_bys:[%Ecto.Query.QueryExpr{expr:sort_expr,params:[]}]}}
239+
sort
240+
|>sanitize_sort()
241+
|>Enum.reduce({:ok,query},fn{order,sort},query->
242+
binding=
243+
caseMap.fetch(query.__ash_bindings__.aggregates,sort)do
244+
{:ok,binding}->
245+
binding
246+
247+
:error->
248+
0
249+
end
250+
251+
{:ok,
252+
from([{^binding,row}]inquery,
253+
order_by:[{^order,field(row,^sort)}]
254+
)}
255+
end)
209256
end
210257

211258
defpsanitize_sort(sort)do
@@ -855,6 +902,6 @@ defmodule AshPostgres.DataLayer do
855902
end
856903

857904
defpmaybe_get_resource_query(resource)do
858-
{table(resource),resource}
905+
{table(Delegate.get_delegated(resource)),resource}
859906
end
860907
end

‎mix.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ defmodule AshPostgres.MixProject do
6161
[
6262
{:ecto_sql,"~> 3.4"},
6363
{:postgrex,">= 0.0.0"},
64-
{:ash,ash_version("~> 1.10")},
64+
{:ash,ash_version("~> 1.11")},
6565
{:git_ops,"~> 2.0.1",only::dev},
6666
{:ex_doc,"~> 0.22",only::dev,runtime:false},
6767
{:ex_check,"~> 0.11.0",only::dev},

‎mix.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%{
2-
"ash":{:hex,:ash,"1.10.0","c3b3eb98ac41da14bb70daeec15d498ea48a91105db9386cb2814eaf38ff0cc6",[:mix],[{:ecto,"~> 3.4",[hex::ecto,repo:"hexpm",optional:false]},{:ets,"~> 0.8.0",[hex::ets,repo:"hexpm",optional:false]},{:nimble_options,"~> 0.3.0",[hex::nimble_options,repo:"hexpm",optional:false]},{:picosat_elixir,"~> 0.1.4",[hex::picosat_elixir,repo:"hexpm",optional:false]}],"hexpm","2a8babe6cfa9fa0274037074ba4a3c23bda9f45a77006c4e745bc6336629a5d1"},
2+
"ash":{:hex,:ash,"1.11.0","cadbe38089f0545905532e393751f3a69e294d5489441102c13b5c8b0b245e6f",[:mix],[{:ecto,"~> 3.4",[hex::ecto,repo:"hexpm",optional:false]},{:ets,"~> 0.8.0",[hex::ets,repo:"hexpm",optional:false]},{:nimble_options,"~> 0.3.0",[hex::nimble_options,repo:"hexpm",optional:false]},{:picosat_elixir,"~> 0.1.4",[hex::picosat_elixir,repo:"hexpm",optional:false]}],"hexpm","e8893bc02f2d687778639a58c0c08ec472d3226217e7e5a3bb1c23ba7fc7cbfd"},
33
"bunt":{:hex,:bunt,"0.2.0","951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38",[:mix],[],"hexpm","7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
44
"certifi":{:hex,:certifi,"2.5.2","b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340",[:rebar3],[{:parse_trans,"~>3.3",[hex::parse_trans,repo:"hexpm",optional:false]}],"hexpm","3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"},
55
"connection":{:hex,:connection,"1.0.4","a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976",[:mix],[],"hexpm","4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp