Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

route-includes-from-window.md

9 lines2.0 KB

Load includes only for the rows a windowed query or a findOne shows. A live query with an orderBy, or a findOne, no longer evaluates the includes in its own select (a child query, toArray, materialize, or findOne) for rows outside the rows it shows, whether limit and offset set the window or setWindow moves it. A late page now costs about the same as the first one. With distinct, the query no longer loads children for every source row. A where that names correlation values starts their child loads at once only when no enclosing query is windowed or a findOne, and either the query is neither windowed nor a findOne, or it is a findOne that shows one row for one named correlation value, with no offset, and offset 0 at start if a window was requested before start. Any other window or findOne, including a window that setWindow requests later, can drop those rows. Includes inherited from a subquery in from, and includes passed into fn.select, still load for every row before the window.

setWindow now moves only the query's own window. A window inside a from subquery, a joined subquery, or an include child no longer answers it, so a query that is neither windowed nor a findOne throws SetWindowRequiresOrderByError, and one that is neither windowed nor an ordered findOne rejects offset moves.

Breaking: a findOne keeps its compiled limit, 1 (or 0 for .limit(0).findOne()). An ordered findOne has a movable window: getWindow() returns { offset, limit } with that limit, and setWindow can move its offset but now throws the new SetWindowFindOneLimitError for any other limit; before, setWindow({ limit: 3 }) made a findOne show three rows. An unordered findOne is a fixed one-row result that accepts only its compiled limit at offset 0: getWindow() returns { offset: 0, limit: 1 }, and a nonzero offset throws SetWindowRequiresOrderByError, as .offset() without orderBy does.