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

Commit6016320

Browse files
committed
fix: adjust to new sorts
1 parentd8cd732 commit6016320

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎lib/ash_postgres.ex‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ defmodule AshPostgres do
120120
end)
121121

122122
changeset=
123-
Map.update!(changeset,:__meta__,&Map.put(&1,:source,resource.postgres_table()))
123+
Map.update!(changeset,:data,fndata->
124+
Map.update!(data,:__meta__,&Map.put(&1,:source,resource.postgres_table()))
125+
end)
124126

125127
repo(resource).insert(changeset)
126128
rescue
@@ -148,21 +150,29 @@ defmodule AshPostgres do
148150
defsort(query,sort,_resource)do
149151
{:ok,
150152
from(rowinquery,
151-
order_by:^sort
153+
order_by:^sanitize_sort(sort)
152154
)}
153155
end
154156

155-
@impltrue
157+
defpsanitize_sort(sort)do
158+
sort
159+
|>List.wrap()
160+
|>Enum.map(fn
161+
{sort,order}->{order,sort}
162+
sort->sort
163+
end)
164+
end
156165

157166
# TODO: I have learned from experience that no single approach here
158167
# will be a one-size-fits-all. We need to either use complexity metrics,
159168
# hints from the interface, or some other heuristic to do our best to
160169
# make queries perform well. For now, I'm just choosing the most naive approach
161170
# possible: left join to relationships that appear in `or` conditions, inner
162-
# join to conditions that are constant the query (inner join not functionalyet.)
171+
# join to conditions that are constant the query (dont do thisyet, but it will be a good optimization)
163172
# Realistically, in my experience, joins don't actually scale very well, especially
164173
# when calculated attributes are added.
165174

175+
@impltrue
166176
deffilter(query,filter,_resource)do
167177
new_query=
168178
query

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp