Every list comes in pages. Without Query.limit, a page has 25 items. The response includes the items and the total number of items that match the filters.
By limit and offset
Section titled “By limit and offset”Query.limit(20) and Query.offset(40) return the third page of 20. It is simple and lets you jump to page N, but it gets slower as the offset grows, and items added or removed along the way change what lands on each page.
By cursor
Section titled “By cursor”Query.cursorAfter(id) starts right after item id (the last one on the previous page). It doesn’t slow down at the end of the list and doesn’t repeat or skip items when the table changes. Use it for infinite scroll and to go through everything:
// Goes through the whole table, 100 rows at a timelet cursor = null;
do { const { rows } = await db.listRows({ databaseId: "loja-principal", tableId: "pedidos", queries: [ Query.limit(100), ...(cursor ? [Query.cursorAfter(cursor)] : []) ], total: false // no need to count }); processar(rows); cursor = rows.length === 100 ? rows[rows.length - 1].$id : null;} while (cursor);// Same code on the server, with @owbase/nodeconst pagina = await db.listRows({ databaseId: "loja-principal", tableId: "pedidos", queries: [Query.limit(20), Query.offset(40)] // 3rd page of 20});curl -G "https://cloud.owbase.dev/v1/tablesdb/loja-principal/tables/pedidos/rows" \--data-urlencode 'queries[]={"method":"limit","values":[100]}' \--data-urlencode 'queries[]={"method":"cursorAfter","values":["6651b02a90f1"]}' \-H "X-Owbase-Project: loja-aurora"Which to use
Section titled “Which to use”| Limit and offset | Cursor | |
|---|---|---|
| Jump to page N | Yes | No |
| Speed at the end of the list | Drops | Constant |
| Repeated items if the table changes | Can happen | No |
| Good for | Tables with numbered pages | Infinite scroll, export |
Counting is expensive
Section titled “Counting is expensive”Calculating the total means counting the rows. When the screen doesn’t show the total, pass total: false: the response comes back faster, with total 0.