Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed May 3, 2022
1 parent f4ceabd commit ce9c6d5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,16 @@ class DB {
public transaction(): ResourceAcquire<DBTransaction> {
return async () => {
const transactionId = this.transactionCounter++;
const tran = await DBTransaction.createTransaction({
const tran = new DBTransaction({
db: this,
transactionId,
logger: this.logger,
});
// const tran = await DBTransaction.createTransaction({
// db: this,
// transactionId,
// logger: this.logger,
// });
return [
async (e?: Error) => {
try {
Expand Down
48 changes: 48 additions & 0 deletions test-iterator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { withF } from '@matrixai/resources';
import { DB } from './src';
import * as testsUtils from './tests/utils';

async function main () {

const key = await testsUtils.generateKey(256);

const db = await DB.createDB({
dbPath: './tmp/db',
crypto: {
key,
ops: { encrypt: testsUtils.encrypt, decrypt: testsUtils.decrypt },
},
fresh: true
});

await db.put('key', 'value');

const p = db.put('key', 'value3');

const t1 = withF([db.transaction()], async ([tran]) => {
const i1 = tran.iterator({ keyAsBuffer: false, valueAsBuffer: false });

console.log('CREATED ITERATOR');

i1.seek('key')
const v1 = (await i1.next())![1];
await i1.end();

const v2 = await tran.get('key');

console.log(v1, v2, v1 === v2);
});

await p;
await t1;

const t2 = withF([db.transaction()], async ([tran]) => {
console.log(await tran.get('key'));
});

await t2;

await db.stop();
}

main();

0 comments on commit ce9c6d5

Please sign in to comment.