🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 06 : 07 : 01
1×
Become a member
to unlock all features
Autoplay

    Paginating and passing other options with Paginate

    Chris BiscardiChris Biscardi
    faunadbFaunaDB

    Paginate can be used with options to move forward or backward in the list of results. We can also limit or expand the number of results we get in a Page.

    Paginate(Match(Index("all_customers")))
    Paginate(Match(Index("all_customers")), { size: 2 })
    Paginate(
      Match(Index("all_customers")),
      {
        size: 2,
        after: Ref(Collection("customers"), "244075679455381001)
      }
    )
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: In FQL, the paginate function takes a setter ref as the first argument. If you read the documentation, it may look like it takes a bunch of arguments after that. Let's take a look at passing the size argument to paginate.

    In the foreign DB shell, we have the function that paginates on the match of the index all customers. If we run this, we can see that we get four results. Let's add a size of two. As you can see, in our data, we now get two refs and then we have the next ref after it. We can expand on this by continuing to paginate.

    If we use the after ref, which is the third ref in the list, and we run this query, we get the last two results, and then we get a before field. As you can see, even though in the documentation it may look like paginate takes many arguments, it actually takes an object as a second argument.