kitsonk / kview

A web app for Deno KV
https://kview.deno.dev
MIT License
69 stars 5 forks source link

Entries with string key parts that parse as integers are not retrievable #10

Closed willianba closed 3 months ago

willianba commented 3 months ago

I have a key for sorting by date that looks like ['items', year, month, itemId]. e.g ['items', '2024', '6', '1']

when navigating to this entity on kview, for example, i can't open the month (6). I do items > 2024 and there's nothing in there.

i don't know if I'm using the wrong type or anything, but I can't make these keys appear on kview unfortunately

kitsonk commented 3 months ago

It isn't you. I think it is a big in the logic for transforming key parts to and from paths used to generate calls to the API. Especially strings that look like numbers. I suspect kview is thinking it is ['items', 2024, 6, 1] instead of ['items', '2024', '6', '1'].

As a side note, you should realise that Deno KV does key ordering based on ordering within JavaScript, so [1], [2], [11] would be the order for number keys while ['1'], ['11'], ['2'] would be the order for string keys.

willianba commented 3 months ago

hmmm maybe i should reconsider making that a number then. thanks for the heads up. i'll update it now, it makes sense, and i'll see if that solves the kview issue too.

willianba commented 3 months ago

yes, it works fine with numbers!

kitsonk commented 3 months ago

There was a defect in the handling of paths that is now fixed and available in 0.14.1. We used to "guess" at if a path part was a number or a string, but that was dangerous and so for it a while, numbers were prefaced with __n__ but the "guessing" logic was removed, so it though /2024/6/1 was [2024, 6, 1] when in fact it was ["2024", "6", "1"] making it unable to be retrieved internally.

willianba commented 3 months ago

thank you for the quick fix! i am not facing it anymore, as i made my indexes use numbers now, but i'm glad i helped somehow 🙌🏻