@davidtkramer/convex-relations 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/index.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -401,9 +401,18 @@ const posts = await q.posts.in(postIds).many();
|
|
|
401
401
|
const categories = await q.categories.bySlug
|
|
402
402
|
.in(["typescript", "convex"])
|
|
403
403
|
.many();
|
|
404
|
+
|
|
405
|
+
// Compound indexes take positional prefixes, one tuple per lookup.
|
|
406
|
+
const comments = await q.comments.byPostIdAndStatus
|
|
407
|
+
.in([
|
|
408
|
+
[postId, "approved"],
|
|
409
|
+
[otherPostId, "pending"],
|
|
410
|
+
])
|
|
411
|
+
.many();
|
|
404
412
|
```
|
|
405
413
|
|
|
406
|
-
|
|
414
|
+
Each value runs as its own index query, in parallel; results are concatenated
|
|
415
|
+
in list order. Batch lookups skip missing rows and dedupe the values.
|
|
407
416
|
|
|
408
417
|
## Relation Expansion with `with(...)`
|
|
409
418
|
|
package/dist/index.js
CHANGED
|
@@ -630,10 +630,27 @@ function createBatchPlan(table, index, values, indexFields) {
|
|
|
630
630
|
kind: "batch",
|
|
631
631
|
table,
|
|
632
632
|
index,
|
|
633
|
-
values,
|
|
633
|
+
values: uniqueBatchValues(values),
|
|
634
634
|
indexFields
|
|
635
635
|
});
|
|
636
636
|
}
|
|
637
|
+
function uniqueBatchValues(values) {
|
|
638
|
+
const seenScalars = /* @__PURE__ */ new Set();
|
|
639
|
+
const seenTuples = [];
|
|
640
|
+
return values.filter((value) => {
|
|
641
|
+
if (!Array.isArray(value)) {
|
|
642
|
+
if (seenScalars.has(value)) return false;
|
|
643
|
+
seenScalars.add(value);
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
if (seenTuples.some((other) => sameBatchValue(other, value))) return false;
|
|
647
|
+
seenTuples.push(value);
|
|
648
|
+
return true;
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
function sameBatchValue(a, b) {
|
|
652
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => Object.is(item, b[index]));
|
|
653
|
+
}
|
|
637
654
|
function isCollectionSource(value) {
|
|
638
655
|
return typeof value === "object" && value !== null && "_plan" in value && "_table" in value;
|
|
639
656
|
}
|