Skip to content

Commit 256abff

Browse files
committed
WIP
1 parent 2432b45 commit 256abff

File tree

3 files changed

+228
-224
lines changed

3 files changed

+228
-224
lines changed

src/DB.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,17 @@ class DB {
473473
options.lt = levelKeyEnd;
474474
}
475475
const iterator = db.iterator(options);
476+
const seek = iterator.seek.bind(iterator);
476477
const next = iterator.next.bind(iterator);
477478
// @ts-ignore AbstractIterator type is outdated
479+
iterator.seek = (k: Buffer | string): void => {
480+
seek(
481+
utils.keyPathToKey(
482+
[...levelPath, k] as unknown as KeyPath
483+
)
484+
);
485+
};
486+
// @ts-ignore AbstractIterator type is outdated
478487
iterator.next = async () => {
479488
const kv = await next();
480489
// If kv is undefined, we have reached the end of iteration

src/DBTransaction.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,14 @@ class DBTransaction {
115115
if (utils.checkSepKeyPath(keyPath as KeyPath)) {
116116
throw new errors.ErrorDBLevelSep();
117117
}
118-
let value: T | undefined;
119-
try {
120-
value = await this.db._get<T>(
121-
[...this.transactionPath, ...keyPath] as unknown as KeyPath,
122-
raw as any
123-
);
124-
} catch (e) {
125-
if (e.notFound) {
126-
value = await this.db.get<T>(keyPath, raw as any);
127-
// Don't set it in the transaction DB
128-
// Because this is not a repeatable-read "snapshot"
129-
} else {
130-
throw e;
131-
}
118+
let value = await this.db._get<T>(
119+
[...this.transactionPath, ...keyPath] as unknown as KeyPath,
120+
raw as any
121+
);
122+
if (value === undefined) {
123+
value = await this.db.get<T>(keyPath, raw as any);
124+
// Don't set it in the transaction DB
125+
// Because this is not a repeatable-read "snapshot"
132126
}
133127
return value;
134128
}
@@ -204,7 +198,7 @@ class DBTransaction {
204198
keyAsBuffer: true,
205199
valueAsBuffer: true
206200
},
207-
['data']
201+
['data', ...levelPath]
208202
);
209203
const tranIterator = this.db._iterator(
210204
this.db.db,
@@ -214,13 +208,13 @@ class DBTransaction {
214208
keyAsBuffer: true,
215209
valueAsBuffer: true
216210
},
217-
this.transactionPath,
211+
[...this.transactionPath, ...levelPath],
218212
);
219213
const order = options?.reverse ? 'desc' : 'asc';
220214
const iterator = {
221215
_ended: false,
222216
_nexting: false,
223-
seek: (k: Buffer | string) => {
217+
seek: (k: Buffer | string): void => {
224218
if (iterator._ended) {
225219
throw new Error('cannot call seek() after end()');
226220
}
@@ -233,7 +227,7 @@ class DBTransaction {
233227
dataIterator.seek(k);
234228
tranIterator.seek(k);
235229
},
236-
end: async () => {
230+
end: async (): Promise<void> => {
237231
if (iterator._ended) {
238232
throw new Error('end() already called on iterator');
239233
}

0 commit comments

Comments
 (0)