Skip to content

Commit

Permalink
use latest keygen and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Sep 7, 2024
1 parent 7531405 commit 44ec4e4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion builder/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function generateIndexDefinition (id, index) {
str += ` name: ${s(index.fqn)},\n`
str += ` encodeKey: ${generateEncodeIndexKey(id, index)},\n`
str += ` encodeKeyRange: ${generateEncodeKeyRange(id, index)},\n`
str += ` encodeValue: (doc) => ${id}.encodeKey(doc),\n`
str += ` encodeValue: (doc) => ${id}.collection.encodeKey(doc),\n`
str += ' reconstruct: (keyBuf, valueBuf) => valueBuf,\n'
str += ' offset: 0,\n'
str += ' collection: null\n'
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class HyperDB {
}
} else {
for (const u of this.updates.values()) {
for (const { key, del } of u.indexes[index.offset]) {
if (withinRange(range, key)) overlay.push({ key, value: del ? null : [u.key, u.value] })
for (const { key, value } of u.indexes[index.offset]) {
if (withinRange(range, key)) overlay.push({ key, value: value === null ? null : [u.key, u.value] })
}
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ class HyperDB {

u.indexes.push(ups)

if (prevKey !== null) ups.push({ key: prevKey, del: true })
if (prevKey !== null) ups.push({ key: prevKey, value: null })
}

this.updates.set(b4a.toString(u.key, 'hex'), u)
Expand Down Expand Up @@ -147,8 +147,8 @@ class HyperDB {

if (prevKey !== null && b4a.equals(nextKey, prevKey)) continue

if (prevKey !== null) ups.push({ key: prevKey, del: true })
if (nextKey !== null) ups.push({ key: nextKey, del: false })
if (prevKey !== null) ups.push({ key: prevKey, value: null })
if (nextKey !== null) ups.push({ key: nextKey, value: idx.encodeValue(doc) })
}

this.updates.set(b4a.toString(u.key, 'hex'), u)
Expand Down
6 changes: 3 additions & 3 deletions lib/engine/rocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ module.exports = class RocksEngine {
else write.delete(u.key)

for (const ups of u.indexes) {
for (const { key, del } of ups) {
if (del === true) write.delete(key)
else write.put(key, u.key)
for (const { key, value } of ups) {
if (value !== null) write.put(key, value)
else write.delete(key)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"hyperdb": "./builder/bin.js"
},
"scripts": {
"test": "standard && brittle test/*.js"
"test": "standard && brittle test/*.js",
"generate": "node builder/bin.js test/fixtures/build.js test/fixtures/generated --force --test-fixture"
},
"dependencies": {
"b4a": "^1.6.6",
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const membersByAgeIndex = {

return memberByAge.encodeRange(r)
},
encodeValue (doc) {
return membersCollection.encodeKey(doc)
},
reconstruct (keyBuf, valueBuf) {
return valueBuf
},
collection: membersCollection
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/generated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const index0 = {
lte: lte ? index0_indexify(lte) : null
})
},
encodeValue: (doc) => index0.encodeKey(doc),
encodeValue: (doc) => index0.collection.encodeKey(doc),
reconstruct: (keyBuf, valueBuf) => valueBuf,
offset: 0,
collection: null
Expand Down

0 comments on commit 44ec4e4

Please sign in to comment.