typicode / lowdb

Simple and fast JSON database
MIT License
21.56k stars 924 forks source link

db.json updates but db.value() does not show it in terminal #576

Closed juniorafonso closed 1 year ago

juniorafonso commented 1 year ago

Hello,

Im very newbie developping and I'm sorry if its a dumb question.

I'm using the v1 still from lowdb bcs im using it as db for my discord bot and i could not make it work with ESM syntax to use the newer version.

But all good so far, it does what needs to do and the only issue I'm having is that when i run a discord command to do anything (set a new object or assign new things) I can see that my db.json file is being modified so everything is working fine. But when I do another command to check my db.json and everything inside doing db.value(). It doesnt show the modification i've done.

So the solution so far was to force a restart of the bot, bcs this way when it goes back online my database is updated.

The thing is that as I said Im learning and rn im trying a bunch of things doing .then() and lets say someone finish registering in the middle of someone registering process, bot would restart so break session and the person would need to start again.

Thats the reason Im trying to make the bot see anymodification in db.json file without restarting the bot.

I know Im maybe trying things outdated and stuff but I rly like using lowdb and it fits perfect my project, that the only issue im having.

Hope you can help me.

Thanks in advance and regards,

juniorafonso commented 1 year ago

https://github.com/typicode/lowdb/issues/449

saved me !

if you get stuck like me, i got different result moving

const databaseFile = 'db.json' const adapter = new FileSync(databaseFile) const db = low(adapter)

just before my db.value()

in the end it was :

const databaseFile = 'db.json'
const adapter = new FileSync(databaseFile)
const db = low(adapter)
db.value()

Sorry but I rly thought I had no more documents to check for helps :D