Load data with Raw SQL statement

The way that you would implement this would be with a manual action:

read :your_legacy_thing do
  manual fn _ash_query, ecto_query, context -> 
    # my suggestion, in order to get the most bang for your buck, is to use Ecto
    # here, and *join* to the ecto_query we provide.
  end
end

If you’re familiar with Ecto, this should be doable. You can also use YourRepo.query! to run raw SQL, but you will have two major drawbacks of this:

  1. you will lose whatever logic Ash already did to honor the original request
  2. you will need to post-process the results into records (not that hard, typically just `Enum.map(…, struct!(Resource, &1))
1 Like