You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seem to write to file entire db on every write operation.
So if i have a db with few 1000 entries,
and i insert a new record 1001,
it will write all 1001 records back to file
with frequent data updates, this can wear off the disk, isnt it
The text was updated successfully, but these errors were encountered:
// Alternatively you can call db.write() explicitely later// to write to db.jsondb.data.posts.push('hello world')awaitdb.write()
Basically, instead of using db.update method, you separate data updates and writes, so you can choose when write-to-disk actually takes place.
In my production app I update lowdb-data all the time, but I write to disk only once in 5 mins AND whenever my app restarts / crashes. The latter is done via signal handlers:
exitEmitter.on('exit',this.#exitHandler.bind(null,{DB}))process.on('SIGINT',this.#exitHandler.bind(null,{DB}))process.on('SIGTERM',this.#exitHandler.bind(null,{DB}))process.on('beforeExit',async()=>awaitthis.#exitHandler.bind(null,{DB}))async #exitHandler({DB}){constmessage='⚠️ ⚠️ ⚠️ has exited, check logs!!! Saving databases before restart ⚠️ ⚠️ ⚠️'awaitDB.writeAllDatabases()awaitsleep(1500)process.exit()}
The app uses and updates ~100 different lowdb objects (heavy multithreading), and to avoid io-related stampede every 5 mins, I slightly randomise writing schedules.
I have been using lowdb for over a year and never lost any data on restart. Disk writes are neither performance nor wear-and-tear issue with such architecture.
Basically, for small objects / arrays (up to several Mb of json worth) I love it.
It seem to write to file entire db on every write operation.
So if i have a db with few 1000 entries,
and i insert a new record 1001,
it will write all 1001 records back to file
with frequent data updates, this can wear off the disk, isnt it
The text was updated successfully, but these errors were encountered: