scrivener_ecto icon indicating copy to clipboard operation
scrivener_ecto copied to clipboard

Allow repo opts to be passed to paginate/2

Open dgigafox opened this issue 3 years ago • 8 comments

Right now we only can pass :prefix repo opt to Repo.paginate/2 but it should behave like a normal repo operation where the user can pass arbitrary/predefined repo options such as those indicated in https://hexdocs.pm/ecto/Ecto.Repo.html#module-shared-options

For example, we should be able to pass :log and :admin as opts to Repo.paginate/2 like this:

Scrivener.Ecto.Repo.paginate(Post, options: [log: true, admin: true])

Now the query will be logged and we can use the arbitrary opts such as admin in the prepare_query/3 callback like so:

@impl true
def prepare_query(_operation, query, opts) do
  if opts[:admin] do
    {query, opts}
  else
    query = from(x in query, where: is_nil(x.deleted_at))
    {query, opts}
  end
end

dgigafox avatar May 21 '22 15:05 dgigafox

This would be a lovely feature to have. My use case is trying to pass the timeout option.

bruno-azenha avatar Aug 09 '22 12:08 bruno-azenha

Neat! I am also hoping for the timeout option to be passable.

@dgigafox are you able to manually run tests on your PR screen? or maybe push an empty commit to trigger the test workflow please?

The maintainer added a test hook for PRs in June after this was opened in May. I'm curious if green tests would make this easier to merge 🙏

Thanks!

DougVonMoser avatar Aug 12 '22 12:08 DougVonMoser

Oh wait, your commit was a year later 🤦 . nevermind me 😅

DougVonMoser avatar Aug 12 '22 12:08 DougVonMoser