One final thought. Your query has no :order
expression. Therefore the rows will be returned in a non-guaranteed order. Which will affect your pagination.
Also note that Scrivener
does an offset/limit
query which has its own challenges, especially on large tables in Postgres. It also can create confusing results if rows are inserted ahead of the current “page”.
You might consider reading the following for ideas and alternatives: