dataloader icon indicating copy to clipboard operation
dataloader copied to clipboard

No way to load "all" records

Open samsondav opened this issue 7 years ago • 2 comments

How can I use dataloader load_many to load all records (not giving any IDs)?

samsondav avatar Sep 11 '18 16:09 samsondav

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.

benwilson512 avatar Sep 11 '18 16:09 benwilson512

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

Yamilquery avatar Sep 25 '18 22:09 Yamilquery

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.

AHBruns avatar Mar 28 '24 03:03 AHBruns

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)

AHBruns avatar Mar 28 '24 03:03 AHBruns