oliver-oloughlin / kvdex

A high-level abstraction layer for Deno KV with zero third-party dependencies by default 🦕🗝️
https://jsr.io/@olli/kvdex
MIT License
192 stars 6 forks source link

The limit parameter error #173

Closed hwcwy closed 8 months ago

hwcwy commented 8 months ago

The limit parameter error restricts the number of items in the filtering process rather than the number of results returned.

import {
  collection,
  kvdex,
  model,
} from "https://deno.land/x/kvdex@0.34.0/mod.ts";

type test = {
  a: number;
};

const kv = await Deno.openKv("test");

const db = kvdex(kv, {
  test: collection(model<test>()),
});

await db.wipe();

for (let i = 1; i <= 100; i++) {
  await db.test.add({ a: i });
}

const res = await db.test.getMany({
  limit: 10,
  filter(v) {
    return v.value.a > 50;
  },
});

console.log(res.result); // It will return []
oliver-oloughlin commented 8 months ago

This is the expected behaviour, when used without offset the limit option directly mimicks the use of limit with kv.list. It's not a limit of results, but of how many items are first pulled from the database.

hwcwy commented 8 months ago

Got it, thank you for your contribution to this library😊