sequelize-paginate icon indicating copy to clipboard operation
sequelize-paginate copied to clipboard

How to retrieve a page containing a particular item (in the middle of a result set)

Open JoeRoddy opened this issue 4 years ago • 0 comments

Thanks for making this library! I've found it super useful :)

Here's my use case:
A user clicks to a video in the middle of a playlist of thousands of videos. I only want to send back the page that includes their video. Then, as they scroll up the playlist, I'll send back previous pages, and as they scroll down I'll send later pages.

Not sure if an option like that exists in this project, here's how I would imagine something like that working:

  const videoId = ARBITRARY_POSITION_IN_PLAYLIST
  const options = {  
    where: { playlistId }, 
    // some option like:
    page: { includes: { id: videoId} }
  };
  const { docs, pages, total, currentPage } = await Videos.paginate(options);
  // also needs to get the "currentPage" of the item, 
  // so the client knows how to grab prev/next item

Is there any type of api for something like this^^? Or will I have to write something custom?

Thanks! -Joe

JoeRoddy avatar Apr 15 '20 01:04 JoeRoddy