Skip to content

Commit 8473ecb

Browse files
committed
WIP
1 parent de0f7d6 commit 8473ecb

File tree

2 files changed

+42
-86
lines changed

2 files changed

+42
-86
lines changed

src/DB.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,6 @@ class DB {
512512
if (kv == null) return kv;
513513
// Handle keys: false
514514
if (kv[0] != null) {
515-
516-
517-
// this should end up returning an empty buffer
518-
// for the empty key
519-
console.log('kv[0]', kv[0]);
520-
console.log('parsed kv[0]', utils.parseKey(kv[0]));
521-
522515
// Truncate level path so the returned key is relative to the level path
523516
const keyPath = utils.parseKey(kv[0]).slice(
524517
levelPath.length
@@ -609,13 +602,6 @@ class DB {
609602
},
610603
levelPath,
611604
)) {
612-
613-
// this is wrong
614-
// because it says [Buffer<...>]
615-
// but it should say [Buffer<...>, Buffer<> ]
616-
// because there's an "empty" key here
617-
console.log('KEYPATH', keyPath);
618-
619605
let k: Buffer | string = utils.keyPathToKey(keyPath);
620606
if (!raw) {
621607
k = k.toString('utf-8');

test-new-iterator.ts

Lines changed: 42 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,64 @@ import * as testsUtils from './tests/utils';
44

55
async function main () {
66

7-
// so the issue is that if a key
8-
// looks like this
9-
// it would have to be parsed to
10-
// ['foobar', '']
11-
// const key = dbUtils.keyPathToKey(
12-
// [
13-
// Buffer.concat([
14-
// dbUtils.sep,
15-
// Buffer.from('data'),
16-
// dbUtils.sep
17-
// ])
18-
// ]
19-
// );
20-
21-
22-
console.log(dbUtils.keyPathToKey([]));
23-
24-
// const keyPath = dbUtils.parseKey(
25-
// Buffer.concat(
26-
// [
27-
// dbUtils.sep,
28-
// Buffer.from('foobar'),
29-
// dbUtils.sep,
30-
// ]
31-
// )
32-
// );
33-
34-
// // This is missing an "empty" buffer
35-
// console.log(keyPath);
36-
37-
// const key = await testsUtils.generateKey(256);
38-
39-
// const db = await DB.createDB({
40-
// dbPath: './tmp/db',
41-
// crypto: {
42-
// key,
43-
// ops: { encrypt: testsUtils.encrypt, decrypt: testsUtils.decrypt },
44-
// },
45-
// fresh: true
46-
// });
7+
const key = await testsUtils.generateKey(256);
8+
9+
const db = await DB.createDB({
10+
dbPath: './tmp/db',
11+
crypto: {
12+
key,
13+
ops: { encrypt: testsUtils.encrypt, decrypt: testsUtils.decrypt },
14+
},
15+
fresh: true
16+
});
4717

48-
// // await db.put('key1', 'value');
49-
// // await db.put('key2', 'value');
50-
// // await db.put('key3', 'value');
51-
// // await db.put(['key3'], 'value');
52-
// // await db.put(['key3', 'key33'], 'value');
18+
// await db.put('key1', 'value');
19+
// await db.put('key2', 'value');
20+
// await db.put('key3', 'value');
21+
// await db.put(['key3'], 'value');
22+
// await db.put(['key3', 'key33'], 'value');
5323

54-
// await db.put([], 'value');
24+
await db.put([], 'value');
5525

56-
// for await (const [kP, v] of db.iterator({
57-
// keyAsBuffer: false,
58-
// valueAsBuffer: false
59-
// })) {
60-
// console.log('ITERATE', [kP, v]);
61-
// }
26+
for await (const [kP, v] of db.iterator({
27+
keyAsBuffer: false,
28+
valueAsBuffer: false
29+
})) {
30+
console.log('ITERATE', [kP, v]);
31+
}
6232

63-
// // false for not raw
64-
// // and this shows up correclty now
65-
// console.dir(await db.dump());
33+
// false for not raw
34+
// and this shows up correclty now
35+
console.dir(await db.dump(['data']));
6636

6737

6838

69-
// // const p = db.put('key', 'value3');
39+
// const p = db.put('key', 'value3');
7040

71-
// // const t1 = withF([db.transaction()], async ([tran]) => {
72-
// // const i1 = tran.iterator({ keyAsBuffer: false, valueAsBuffer: false });
41+
// const t1 = withF([db.transaction()], async ([tran]) => {
42+
// const i1 = tran.iterator({ keyAsBuffer: false, valueAsBuffer: false });
7343

74-
// // console.log('CREATED ITERATOR');
44+
// console.log('CREATED ITERATOR');
7545

76-
// // i1.seek('key')
77-
// // const v1 = (await i1.next())![1];
78-
// // await i1.end();
46+
// i1.seek('key')
47+
// const v1 = (await i1.next())![1];
48+
// await i1.end();
7949

80-
// // const v2 = await tran.get('key');
50+
// const v2 = await tran.get('key');
8151

82-
// // console.log(v1, v2, v1 === v2);
83-
// // });
52+
// console.log(v1, v2, v1 === v2);
53+
// });
8454

85-
// // await p;
86-
// // await t1;
55+
// await p;
56+
// await t1;
8757

88-
// // const t2 = withF([db.transaction()], async ([tran]) => {
89-
// // console.log(await tran.get('key'));
90-
// // });
58+
// const t2 = withF([db.transaction()], async ([tran]) => {
59+
// console.log(await tran.get('key'));
60+
// });
9161

92-
// // await t2;
62+
// await t2;
9363

94-
// await db.stop();
64+
await db.stop();
9565
}
9666

9767
main();

0 commit comments

Comments
 (0)