Skip to content

Commit fbad527

Browse files
authored
Implement has() and hasMany() (#18)
Ref: Level/community#142 Category: addition
1 parent f832018 commit fbad527

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

index.js

+19
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class MemoryLevel extends AbstractLevel {
290290
permanence: false,
291291
createIfMissing: false,
292292
errorIfExists: false,
293+
has: true,
293294
encodings: { [storeEncoding]: true },
294295
signals: {
295296
// Would have no value here because the operations are synchronous
@@ -327,6 +328,20 @@ class MemoryLevel extends AbstractLevel {
327328
return keys.map(getFromThis, tree)
328329
}
329330

331+
async _has (key, options) {
332+
const tree = options.snapshot != null
333+
? options.snapshot[kTree]
334+
: this[kTree]
335+
return tree.get(key) !== undefined
336+
}
337+
338+
async _hasMany (keys, options) {
339+
const tree = options.snapshot != null
340+
? options.snapshot[kTree]
341+
: this[kTree]
342+
return keys.map(has, tree)
343+
}
344+
330345
async _del (key, options) {
331346
this[kTree] = this[kTree].remove(key)
332347
}
@@ -423,3 +438,7 @@ function getFromThis (key) {
423438
function isRangeOption (k) {
424439
return rangeOptions.has(k)
425440
}
441+
442+
function has (key) {
443+
return this.get(key) !== undefined
444+
}

0 commit comments

Comments
 (0)