You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to directly retrieve all sublevels through the Level API, but I couldn't find any relevant APIs. Instead of using a method that involves reading all keys and looping through them to check if they contain certain characters, I think it would be more efficient to store a small index when creating the sublevel.
The text was updated successfully, but these errors were encountered:
In a relational database we would group by a part of a compound key to see if a category of entries is present.
sublevel key value ========================= example 19 [object] example 20 [object] another a [object]
select sublevel from kvstore group by sublevel
This can still fully scan the table, but can also try to get the index stats instead select sublevel, count(*) from kvstore group by sublevel
In a key-value db when we concatenate category into a key, it would be nice if the sublevels are tracked somehow
key value ======================= !example!19 [object] !example!20 [object] !another!a [object]
You can use the database itself as an index and query it with a skip scan to discover sublevels. Roughly like so (not fully tested):
const{ AbstractSublevel }=require('abstract-level')// Discover sublevels using a skip scanasyncfunctionsublevels(db,options){constseparator=AbstractSublevel.defaults(options).separatorconstupperBound=String.fromCharCode(separator.charCodeAt(0)+1)constiterator=db.keys({keyEncoding: 'utf8'})constnames=[]try{lettarget=separatorwhile(true){iterator.seek(target)constkey=awaititerator.next()// Stop if no sublevel prefix is foundif(key===undefined||key[0]!==separator){break}// Check if key has a complete sublevel prefix, e.g. '!a!'consti=key.indexOf(separator,1)if(i===-1)break// Extract name, e.g. 'a'constname=key.slice(1,i)names.push(name)// Seek to next sublevel that follows '!a"'target=separator+name+upperBound}}finally{awaititerator.close()}returnnames}
I want to directly retrieve all sublevels through the Level API, but I couldn't find any relevant APIs. Instead of using a method that involves reading all keys and looping through them to check if they contain certain characters, I think it would be more efficient to store a small index when creating the sublevel.
The text was updated successfully, but these errors were encountered: