dataloader
dataloader copied to clipboard
No way to load "all" records
How can I use dataloader load_many to load all records (not giving any IDs)?
Short answer: There isn't a way right now.
Longer answer: The whole of Dataloader is predicated on a key / value paradigm. This is true even for the ecto source and ecto associations, where when you load something like comments on a post the key is {some_post, :comments} and the value is all the comments. So what we'd need for Dataloader to load all posts is a key that looked like {%Dataloader.Root{}, :posts}. As of yet such a root value has not been specified. This is a feature I'm considering for 1.1
Notably, a PR is absolutely welcome on this front.
Yes. As @benwilson512 said, Dataloader is predicted on a key-value paradigm. So if you want to get a more detailed knowledge about it, take a look to Using Dataloader to Batch Request
I'm wondering if there is a plan to implement this since, as of now, it still seems impossible despite the issue being closed as completed.
I was able to get a this working though
Dataloader.Ecto.new(Melzi.Repo,
run_batch: fn
_queryable, query, :id, ["*"], repo_opts ->
[Melzi.Repo.all(query, repo_opts)]
queryable, query, col, inputs, repo_opts ->
Dataloader.Ecto.run_batch(Melzi.Repo, queryable, query, col, inputs, repo_opts)
end
)
This lets me do this
loader
|> Dataloader.load(Melzi.Data, {:many, Melzi.Data.Person}, "*")
|> on_load(fn loader ->
{:ok, Dataloader.get(loader, Melzi.Data, {:many, Melzi.Data.Person}, "*")}
end)