Pagination: With remote API and DB combined - devrath/ComposeAlchemy GitHub Wiki

Steps involved

  • Fetch the data from the API.
  • Save the data in DB.
  • A table is needed to store the data list
  • Another table is needed to store the keys
    • This table is needed for the calculation of nextKey and prevKey
  • There are 3 types of operations
    • First-time fetch or refresh
    • Prepend
    • Append

Visualizing how the tables are used

  • As seen in the image observe there would be two tables
  • The first table is used to store the data & second table is used to store the corresponding keys for each data from the first table.
  • See the first table has 3 pages represented by three colors, Now we know that each row has a unique identifier key.
  • The second table has 3 columns, First column has ID of each row from the first table. The second column has the previous key and finally the third column has the next key.
  • Observe the previous key of the first page is null and the next key is 1.
  • Also observe here the previous key of the second page is 1 and the next key is 2.
  • The previous key being null indicates this page is the first page.
  • The next key being null indicates that this is the last page.