Skip to content

Commit ce9c6d5

Browse files
committed
WIP
1 parent f4ceabd commit ce9c6d5

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/DB.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,16 @@ class DB {
159159
public transaction(): ResourceAcquire<DBTransaction> {
160160
return async () => {
161161
const transactionId = this.transactionCounter++;
162-
const tran = await DBTransaction.createTransaction({
162+
const tran = new DBTransaction({
163163
db: this,
164164
transactionId,
165165
logger: this.logger,
166166
});
167+
// const tran = await DBTransaction.createTransaction({
168+
// db: this,
169+
// transactionId,
170+
// logger: this.logger,
171+
// });
167172
return [
168173
async (e?: Error) => {
169174
try {

test-iterator.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { withF } from '@matrixai/resources';
2+
import { DB } from './src';
3+
import * as testsUtils from './tests/utils';
4+
5+
async function main () {
6+
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+
});
17+
18+
await db.put('key', 'value');
19+
20+
const p = db.put('key', 'value3');
21+
22+
const t1 = withF([db.transaction()], async ([tran]) => {
23+
const i1 = tran.iterator({ keyAsBuffer: false, valueAsBuffer: false });
24+
25+
console.log('CREATED ITERATOR');
26+
27+
i1.seek('key')
28+
const v1 = (await i1.next())![1];
29+
await i1.end();
30+
31+
const v2 = await tran.get('key');
32+
33+
console.log(v1, v2, v1 === v2);
34+
});
35+
36+
await p;
37+
await t1;
38+
39+
const t2 = withF([db.transaction()], async ([tran]) => {
40+
console.log(await tran.get('key'));
41+
});
42+
43+
await t2;
44+
45+
await db.stop();
46+
}
47+
48+
main();

0 commit comments

Comments
 (0)