My use case is the following. I have an umbrella application that clearly separates the DB access layer from the business logic. By doing this, I don’t want to directly expose the DB resources to the other applications.
Instead, what I want is to have an edge interface that will expose the DB resource, and a receiver that will do the conversion from the “DB resource” struct, to an internal POEXS (plain old Elixir struct).
I know it might be overcomplicating things, but I want to see how far I can get with this approach.
What bothers me is that I don’t see a way to directly transform StructA into StructB.
So if I have:
%DB.FooResource{name: "bar"}
And I’d like to convert it into:
%MyApp.Foo{name: "bar"}
What I’d need to do is to convert the first one into a map, and create a struct from that map.
data = db_resource |> Map.from_struct()
struct(MyApp.Foo, data)
A bit cumbersome in my opinion, especially if you get an array of those.
Is there a better way of doing this, or is it cumbersome, because it’s a wrong approach?