Closed tbaumann closed 8 months ago
I think what you want to do is probably something like:
const MAX_VALUE = '\uffff'; // can be imported from ordered-binary
myDB.getRange({ start: ["com", "example", "bar"], end: ["com", "example", "bar", MAX_VALUE]}).forEach(entry => {
console.log("Subdomain:" , entry.value);
})
Nice. That's what I needed. Much cleaner than maintaining a separate index. And I assume this still takes advantage of the primary index for performance?
I assume this still takes advantage of the primary index for performance?
Yes, for sure. O(log n) access with amortized constant time traversal.
Nice, I think I'm beginning to understand what the magic behind that is.
Thanks a lot for the help.
const ordered_binary = require('ordered-binary'); const MAX_VALUE = ordered_binary.MAXIMUM_KEY;
That doesn't work. Your '\uffff' above does
I need to store entries by domain name in the DB. But sometimes I need to select by subdomain.
If I have foo.bar.example.com and baz.example.com I may sometimes need to select those entries by example.com.
The solution seems obvious. I need to maintain a separate DB with indexes by subdomains for every level.
But there is a sentence in the documentation that made me pause.
Can I somehow use that if I store the domain in reverse as an array?
Quick testing suggests that there is only one key per entry and it only matches on the entire array.
Output