kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
481 stars 39 forks source link

db.ifNoExists() not functioning properly in transaction #228

Open NFTYieldFarm opened 1 year ago

NFTYieldFarm commented 1 year ago

If I run this exact code outside of a transaction it behaves properly, if I write it inside of a transaction, it behaves abnormally.

function addKey(key: string, name: string) { db.get(key) // { test } db.put(key, { name }); db.get(key) // { test2 } }

db.transaction(async () => { const exists = await db.ifNoExists(key, () => addKey(key, "test2")); // regardless if exists resolves to true or false, it is still changing name from test to test2. }

kriszyp commented 1 year ago

I can't reproduce this, with this code. It seems to properly call addKey when the entry for the key doesn't exist and doesn't call it when it does exist. Are you using the latest version? Do you have a more complete/reproducible case?