@@ -14,7 +14,7 @@ defmodule AshPostgres do
1414]
1515)
1616
17- alias Ash.Filter . { And , Eq , Filter , In , NotEq , NotIn , Or }
17+ alias Ash.Filter . { And , Eq , In , NotEq , NotIn , Or }
1818
1919@ moduledoc """
2020 A postgres data layer that levereges Ecto's postgres tools.
@@ -101,7 +101,8 @@ defmodule AshPostgres do
101101end
102102
103103@ impl true
104- def resource_to_query ( resource ) , do: Ecto.Queryable . to_query ( resource )
104+ def resource_to_query ( resource ) ,
105+ do: Ecto.Queryable . to_query ( { resource . postgres_table ( ) , resource } )
105106
106107@ impl true
107108def create ( resource , changeset ) do
@@ -111,6 +112,9 @@ defmodule AshPostgres do
111112action -> action
112113end )
113114
115+ changeset =
116+ Map . update! ( changeset , :__meta__ , & Map . put ( & 1 , :source , resource . postgres_table ( ) ) )
117+
114118repo ( resource ) . insert ( changeset )
115119rescue
116120e ->
@@ -125,6 +129,14 @@ defmodule AshPostgres do
125129{ :error , e }
126130end
127131
132+ @ impl true
133+ def destroy ( % resource { } = record ) do
134+ repo ( resource ) . delete ( record )
135+ rescue
136+ e ->
137+ { :error , e }
138+ end
139+
128140@ impl true
129141def sort ( query , sort , _resource ) do
130142{ :ok ,
@@ -134,6 +146,7 @@ defmodule AshPostgres do
134146end
135147
136148@ impl true
149+
137150# TODO: I have learned from experience that no single approach here
138151# will be a one-size-fits-all. We need to either use complexity metrics,
139152# hints from the interface, or some other heuristic to do our best to