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

Commitd8cd732

Browse files
Merge pull requestash-project#2 from ash-project/generate-resources
Postgres Tables
2 parents4c072b8 +7ce79ef commitd8cd732

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

‎lib/ash_postgres.ex‎

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
defmoduleAshPostgresdo
22
@using_opts_schemaAshton.schema(
33
opts:[
4-
repo::atom
4+
repo::atom,
5+
table::string
56
],
67
required:[:repo],
78
describe:[
89
repo:
9-
"The repo that will be used to fetch your data. See the `Ecto.Repo` documentation for more"
10+
"The repo that will be used to fetch your data. See the `Ecto.Repo` documentation for more",
11+
table:"The name of the database table backing the resource"
1012
],
1113
constraints:[
1214
repo:
@@ -31,10 +33,15 @@ defmodule AshPostgres do
3133

3234
@data_layerAshPostgres
3335
@repoopts[:repo]
36+
@tableopts[:table]
3437

3538
defrepo()do
3639
@repo
3740
end
41+
42+
defpostgres_table()do
43+
@table||@name
44+
end
3845
end
3946
end
4047

@@ -217,13 +224,16 @@ defmodule AshPostgres do
217224
end
218225

219226
defpdo_join_relationship(query,[%{type::many_to_many}=relationship],:inner)do
227+
relationship_through=maybe_get_resource_query(relationship.through)
228+
relationship_destination=maybe_get_resource_query(relationship.destination)
229+
220230
new_query=
221231
from(rowinquery,
222-
join:throughin^relationship.through,
232+
join:throughin^relationship_through,
223233
on:
224234
field(row,^relationship.source_field)==
225235
field(through,^relationship.source_field_on_join_table),
226-
join:destinationin^relationship.destination,
236+
join:destinationin^relationship_destination,
227237
on:
228238
field(destination,^relationship.destination_field)==
229239
field(through,^relationship.destination_field_on_join_table)
@@ -238,23 +248,28 @@ defmodule AshPostgres do
238248
end
239249

240250
defpdo_join_relationship(query,[relationship],:inner)do
251+
relationship_destination=maybe_get_resource_query(relationship.destination)
252+
241253
new_query=
242254
from(rowinquery,
243-
join:destinationin^relationship.destination,
255+
join:destinationin^relationship_destination,
244256
on:field(row,^relationship.source_field)==field(row,^relationship.destination_field)
245257
)
246258

247259
add_binding(new_query,[relationship.name],:inner)
248260
end
249261

250262
defpdo_join_relationship(query,[%{type::many_to_many}=relationship],:left)do
263+
relationship_through=maybe_get_resource_query(relationship.through)
264+
relationship_destination=maybe_get_resource_query(relationship.destination)
265+
251266
new_query=
252267
from(rowinquery,
253-
left_join:throughin^relationship.through,
268+
left_join:throughin^relationship_through,
254269
on:
255270
field(row,^relationship.source_field)==
256271
field(through,^relationship.source_field_on_join_table),
257-
left_join:destinationin^relationship.destination,
272+
left_join:destinationin^relationship_destination,
258273
on:
259274
field(destination,^relationship.destination_field)==
260275
field(through,^relationship.destination_field_on_join_table)
@@ -269,9 +284,11 @@ defmodule AshPostgres do
269284
end
270285

271286
defpdo_join_relationship(query,[relationship],:left)do
287+
relationship_destination=maybe_get_resource_query(relationship.destination)
288+
272289
new_query=
273290
from(rowinquery,
274-
left_join:destinationin^relationship.destination,
291+
left_join:destinationin^relationship_destination,
275292
on:field(row,^relationship.source_field)==field(row,^relationship.destination_field)
276293
)
277294

@@ -433,4 +450,12 @@ defmodule AshPostgres do
433450
deftransaction(resource,func)do
434451
repo(resource).transaction(func)
435452
end
453+
454+
defpmaybe_get_resource_query(resource)do
455+
ifAsh.resource_module?(resource)do
456+
{resource.postgres_table(),resource}
457+
else
458+
resource
459+
end
460+
end
436461
end

‎lib/migration.exs‎

Whitespace-only changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp