Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NFTYieldFarm opened this issue May 6, 2023 · 1 comment
Open

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

NFTYieldFarm opened this issue May 6, 2023 · 1 comment

Comments

@NFTYieldFarm
Copy link

NFTYieldFarm commented May 6, 2023

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
Copy link
Owner

kriszyp commented May 9, 2023

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?

kriszyp added a commit that referenced this issue May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants