Skip to content
Source
Sign inSign up
TanStack/db

Modify topK and orderBy to track by key instead of by object reference #405

Mergedkevin-dp(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/405/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Showing 8 changed files with 226 additions and 0 deletions (loading 6).

x
0 of 8 viewed, 8 left
6 additions and 0 deletions.changeset/polite-islands-kiss.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+"@tanstack/db-ivm": patch
+"@tanstack/db": patch
+---
+​
+Fix bug with orderBy that resulted in query results having less rows than the configured limit.
220 additions and 0 deletionspackages/db/tests/query/order-by.test.tsModified
View file
@@ -398,6 +398,226 @@
`LIMIT and OFFSET require an ORDER BY clause to ensure deterministic results`
+​
+ it(`applies incremental insert of a new row before the topK correctly`, async () => {
+ const collection = createLiveQueryCollection((q) =>
+ q
+ .from({ employees: employeesCollection })
+ .orderBy(({ employees }) => employees.salary, `desc`)
+ .offset(1)
+ .limit(2)
+ .select(({ employees }) => ({
+ id: employees.id,
+ name: employees.name,
+ salary: employees.salary,
+ }))
+ )
+ await collection.preload()
+​
+ const results = Array.from(collection.values())